带有乱码 UTF-8 字符的 Android WebView. [英] Android WebView with garbled UTF-8 characters.
本文介绍了带有乱码 UTF-8 字符的 Android WebView.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在我的 android 应用中使用了一些 webview,但无法让它们以 utf-8 编码显示.
I'm using some webviews in my android app, but are unable to make them display in utf-8 encoding.
如果使用这个,我将看不到我的斯堪的纳维亚字符:
If use this one I won't see my scandinavian charcters:
mWebView.loadUrl("file:///android_asset/om.html")
如果尝试这个,我根本不会显示任何内容
And if try this one, I won't get anything displayed at all
mWebView.loadDataWithBaseURL("file:///android_asset/om.html", null, "text/html", "utf-8",null);
问候
推荐答案
您可以尝试在加载数据之前编辑 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");
这篇关于带有乱码 UTF-8 字符的 Android WebView.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文