Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
223 views
in Technique[技术] by (71.8m points)

Android WebView with garbled UTF-8 characters.

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);

Regards

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

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

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");

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...