Android webview load html code

During the development process, some text and pictures are displayed. Things that do not require interaction usually return html code in the background. We only need to load the code with webview, but after obtaining it, there are many special symbols that cannot be recognized. We need to change the code. Replace the special symbols in to load successfully.

Common special symbols are as follows, if you don’t have one, you can Baidu it, a lot

The specific code is as follows:

WebSettings ws = webView.getSettings();
        ws.setUserAgentString("56renapp1234321");
        ws.setJavaScriptEnabled(false);
        ws.setAllowFileAccess(true);
        ws.setBuiltInZoomControls(false);
        ws.setSupportZoom(false);
        ws.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
        ws.setDefaultTextEncodingName("utf-8"); //设置文本编码
        ws.setAppCacheEnabled(true);
        ws.setCacheMode(WebSettings.LOAD_DEFAULT);//设置缓存模式</span>
        if (StringUtils.isNotEmpty(content)) {
            content = content.replaceAll("&amp;", "");
            content = content.replaceAll("&quot;", "\"");
            content = content.replaceAll("&lt;", "<");
            content = content.replaceAll("&gt;", ">");
            content = content.replaceAll("&nbsp;", "");
            webView.setHorizontalScrollBarEnabled(false);//水平不显示
            webView.setVerticalScrollBarEnabled(false); //垂直不显示
            webView.loadDataWithBaseURL(null, content, "text/html", "utf-8", null);
        } 

 

Guess you like

Origin blog.csdn.net/u010256329/article/details/97271829