[英]Can't show certain UTF-8 characters in android webview
I know this problem has been documented elsewhere but the solutions don't seem to work for me. 我知道这个问题已在其他地方记录,但解决方案似乎对我不起作用。 Other similar questions:
其他类似问题:
Android WebView with garbled UTF-8 characters. 带有乱码的UTF-8字符的Android WebView。
Android WebView UTF-8 not showing Android WebView UTF-8不显示
I'm essentially trying to show the minus/plus character (∓) in an android webview. 我实质上是想在Android Webview中显示减号/加号(∓)。 I tested several other characters 'around' the minus plus character in the UTF-8 table but some of them didn't work either
我在UTF-8表中测试了负号附近的其他几个字符,但其中一些也不起作用
Here is the java im using: 这是java im使用:
final WebView w = (WebView) findViewById(R.id.webview1);
w.getSettings().setJavaScriptEnabled(true);
w.getSettings().setDefaultTextEncodingName("utf-8");
InputStream is;
try {
is = getAssets().open("test5.html");
int size = is.available();
byte[] buffer = new byte[size];
is.read(buffer);
is.close();
String str = new String(buffer);
w.loadData(str, "text/html; charset=utf-8", "utf-8");
Here is the html test5.html 这是html test5.html
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
char: ∓ <br/>
char: ∔ <br/>
char: ∕ <br/>
char: ∖ <br/>
char: ∗ <br/>
char: ∘ <br/>
</body>
The only characters that show up are the "∕" and "∗". 出现的唯一字符是“ ∕”和“ *”。 I've also tried
我也尝试过
w.loadDataWithBaseURL("file:///doesnotmatter", str, "text/html", "utf-8", "");
with no success. 没有成功。 I'm not too familiar with the input stream thing so I don't know if there's something wrong there.
我对输入流内容不太熟悉,所以我不知道那里是否有问题。 Please help, its taken me awhile =\\
请帮助,它花了我一段时间= \\
-Teneth -Teneth
调用loadData()时 ,将编码以大写形式“ UTF-8”传递,因为它区分大小写,并且是文档中的标准表示形式。
use html codes for that characters in your html file: 在html文件中对该字符使用html代码:
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
char: ∓<br/>
char: ∔<br/>
char: ∕<br/>
char: ∖<br/>
char: ∗<br/>
char: ∘<br/>
</body>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.