Search code examples
javaandroidandroid-webview

WebView issue new update android operative system


Recently some devices stop working webview components, I detected that android 8 and android 6 or fewers works all rigth but in devices with android 7 o 9 there is not text showing. This problem started in the lastest weeks. I have not update the app since February 2018

descripcion = (WebView) findViewById(R.id.txt_descripcion);

String description="<html><body><head><style type=\"text/css\">\n" +
            "p {\n" +
            "font-size:90%;text-indent: 1em; text-align:justify; \n" +
            "}\n" +"body {font-family: Arial, Helvetica, sans-serif;}\n" +
            "\n" +
            "table {     font-family: \"Lucida Sans Unicode\", \"Lucida Grande\", Sans-Serif;\n" +
            "    font-size: 12px;     width: 100%; text-align: left;    border-collapse: collapse; }\n" +
            "\n" +
            "th {     font-size: 13px;     font-weight: normal;          background: #b9c9fe;\n" +
            "    border-top: 4px solid #aabcfe;    border-bottom: 1px solid #fff; color: #039; }\n" +
            "\n" +
            "td {         background: #e8edff;     border-bottom: 1px solid #fff;\n" +
            "    color: #669;    border-top: 1px solid transparent; }\n" +
            "\n" +
            "tr:hover td { background: #d0dafd; color: #339; }"+
            "</style></head><p>"+hechizo.getDescripcion()+"</p></body></html>";

descripcion.loadData(description,"text/html; charset=UTF-8",null);

Solution

  • Try this:

    WebSettings settings = myWebView.getSettings();
    settings.setDefaultTextEncodingName("utf-8");
    myWebView.loadDataWithBaseURL(null, htmlString, "text/html", "utf-8", null);