2016-08-21 89 views
1

當我使用utf-8時,我webview中的字符被破壞。它在黑色鑽石背景上顯示問號。當我使用其他編碼時,它們會出現亂碼。我試着從this thread的解決方案,我的代碼看起來像Android webview葡萄牙文字符

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)字符出現亂碼。

回答

1

您可以使用HTML代碼保存在XML,但是,這主要是沒有必要,如果他們是在UTF-8符號,實際字符也會做:

<string name="my_string">&#65;</string> 

或者,你可以調用的setText ()與TextView的統一:

textView.setText("\u266b"); 

在這裏,這將幫助你更: 2個網站,我個人使用在冰島寫,你RAE尋找每一個字符列在其中

Characters table website 1

Characters table website 2