机器人的WebView UTF-8不显示 [英] Android WebView UTF-8 not showing

查看:176
本文介绍了机器人的WebView UTF-8不显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个web视图,我试图加载简单的UTF-8文本内容。

I have a webview and am trying to load simple UTF-8 text into it.

mWebView.loadData("將賦予他們的傳教工作標示為", "text/html", "UTF-8");

但web视图显示ANSI / ASCII垃圾。

But the WebView displays ANSI/ASCII garbage.

显然编码的问题,但是我在告诉web视图显示统一code文本丢失?

Obviously an encoding issue, but what am I missing in telling the webview to display the Unicode text?

这是一个HelloWorld应用程序。

This is a HelloWorld app.

推荐答案

使用:

mWebView.loadDataWithBaseURL(null, "將賦予他們的傳教工作標示為", "text/html", "utf-8", null);

或使用WebSettings与<一个href="http://developer.android.com/reference/android/webkit/WebSettings.html#setDefaultTextEncodingName%28java.lang.String%29">setDefaultTextEncoding:

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

为Android,API的16至22是进行了测试,工作正常使用loadData()方法的最新版本,需要MIMETYPE包括:字符集= UTF-8

WebView mWebView = (WebView) findViewById(R.id.myWebView);
WebSettings settings = mWebView.getSettings();
settings.setDefaultTextEncodingName("utf-8");                   
mWebView.loadData(topHtml, "text/html; charset=utf-8",null);

这篇关于机器人的WebView UTF-8不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆