安卓.WebView 和 loadData [英] Android. WebView and loadData
问题描述
可以使用以下方法设置网页视图的内容loadData(String data, String mimeType, String encoding)
It's possible to use following method for content's setting of a web-view loadData(String data, String mimeType, String encoding)
如何处理html数据编码未知的问题?!
How to handle the problem with unknown encoding of html data?!
有编码列表吗?!
我从我的大学知道,就我而言,html 来自 DB 并使用 latin-1 编码.我尝试将编码参数设置为 latin-1、ISO-8859-1/iso-8859-1,但仍然无法显示 ä、ö、ü 等特殊符号.
I know from my college that in my case html comes from DB and is encoded with latin-1. I try to set encoding parameter to latin-1, to ISO-8859-1 / iso-8859-1, but still have problem with displaying of special signs like ä, ö, ü.
我将非常感谢您的任何建议.
I'll be very thankful for any advice.
推荐答案
myWebView.loadData(myHtmlString, "text/html; charset=UTF-8", null);
这完美无缺,尤其是在 Android 4.0 上,它显然忽略了内部 HTML 的字符编码.
This works flawlessly, especially on Android 4.0, which apparently ignores character encoding inside HTML.
在 2.3 和 4.0.3 上测试过.
Tested on 2.3 and 4.0.3.
事实上,我不知道最后一个参数除了base64"之外还有什么其他值.一些 Google 示例将 null 放在那里.
In fact, I have no idea about what other values besides "base64" does the last parameter take. Some Google examples put null in there.
这篇关于安卓.WebView 和 loadData的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!