Android webview葡萄牙语字符

标签 android encoding utf-8 webview

当我使用 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">&#65;</string>

或者,您可以在 TextView 上使用 unicode 调用 setText():

textView.setText("\u266b");

这将对您有更多帮助: 我个人用冰岛语写作的两个网站,你想找的每一个字符都列在那里

Characters table website 1

Characters table website 2

关于Android webview葡萄牙语字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39065110/

相关文章:

ios - 修补应用内购买黑客;卡在第四步

ruby-on-rails - 尽管在 Heroku 上使用 Rails 设置了新的参数组,但无法在 RDS 中存储 UTF-8

.net - StreamReader.ReadToEnd()使用什么字符编码?

c - 用C语言对数据进行编码和解码

android - 第一次上传 Android studio 项目到 Subversion

android - 在 Android 上的 RxJava2 中结合 Singles 的最佳方式?

android - 按需显示/隐藏 Listview SectionIndex

emacs - emacs中各种类型的 'utf-8'有什么区别

java - Avro 和 java : deserialized map of string doesn't "equals" original map

java - parseInt 时 SQLite 错误