当我使用 utf-8 时,我的 webview 中的字符被破坏了。它在黑色菱形背景上显示问号。当我使用其他编码时,它们会出现乱码。我试过来自 this thread 的解决方案,我的代码看起来像
input = assetManager.open("xxx.html");
Integer size = input.available();
byte[] buffer = new byte[size];
input.read(buffer);
text = new String(buffer);
WebSettings settings = webView.getSettings();
settings.setDefaultTextEncodingName("utf-8");
webView.loadDataWithBaseURL("file:///android_asset/",text,"text/html; charset=utf-8", "utf-8",null);
HTML 标题
<html ><head><meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<meta name="xxxxx">
<title>xxx</title>
<style type="text/css">
@font-face {
font-family: fonttt;
src: url("file:///android_asset/roboto.ttf")
}
body {
font-family: fonttt;
font-size: medium;
text-align: justify;
}
</style>
</head>
我不明白为什么 utf-8 不起作用以及为什么当我使用其他编码(windows-1252、ISO-8859-1)时字符会出现乱码。
最佳答案
您可以使用 html 代码将它们保存在 xml 中,但是,如果它们采用 UTF-8 表示法,则通常不需要这样做,实际字符也可以:
<string name="my_string">A</string>
或者,您可以在 TextView 上使用 unicode 调用 setText():
textView.setText("\u266b");
这将对您有更多帮助: 我个人用冰岛语写作的两个网站,你想找的每一个字符都列在那里
关于Android webview葡萄牙语字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39065110/