且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

带有乱码 UTF-8 字符的 Android WebView.

更新时间:2023-11-27 18:49:16

您可以尝试在加载数据之前编辑 webview 的设置:

You can try to edit the settings of your webview before you load the data:

WebSettings settings = mWebView.getSettings();
settings.setDefaultTextEncodingName("utf-8");

此外,如以下注释中所提供,请务必将 "charset=utf-8" 添加到 loadData 调用中:

Also, as provided in the comment below, be sure to add "charset=utf-8" to the loadData call:

mWebView.loadData(getString(R.string.info_texto), "text/html; charset=utf-8", "utf-8");