第一步:
mWebView.getSettings().setDefaultTextEncodingName("UTF-8");
第二步:
mWebView.loadData(data, "text/html; charset=UTF-8", null);
WebView常用配置:
private void initWebView() { mWebView.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN); mWebView.getSettings().setDefaultTextEncodingName("UTF-8"); mWebView.getSettings().setJavaScriptEnabled(true); mWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); mWebView.getSettings().setSupportZoom(true); mWebView.getSettings().setDomStorageEnabled(true); mWebView.getSettings().setAllowFileAccess(true); mWebView.getSettings().setUseWideViewPort(true); mWebView.getSettings().setBuiltInZoomControls(true); mWebView.getSettings().setLoadWithOverviewMode(true); mWebView.requestFocus(); mWebView.loadUrl(url); mWebView.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { return super.shouldOverrideUrlLoading(view, url); } @Override public void onLoadResource(WebView view, String url) { super.onLoadResource(view, url); } @Override public void onPageStarted(WebView view, String url, android.graphics.Bitmap favicon) { }; @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); } }); }