webView 加载html代码乱码

String content = String.format("%s%s%s", "",detail,"");


wvContent.loadDataWithBaseURL(content, "text/html", "utf-8"); 错误的


正确的显示方式:

wvContent.loadDataWithBaseURL(null,content, "text/html", "utf-8",null); 

WebView wvContent =  (WebView) findViewById(R.id.wv_content);
WebSettings ws = wvContent.getSettings();
ws.setJavaScriptEnabled(false);
ws.setAllowFileAccess(true); 
ws.setBuiltInZoomControls(false);
ws.setSupportZoom(false);  
ws.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN );
ws.setDefaultTextEncodingName("utf-8"); //设置文本编码
ws.setAppCacheEnabled(true);
ws.setCacheMode(WebSettings.LOAD_DEFAULT);//设置缓存模式

你可能感兴趣的:(安卓开发)