Web视图中未显示特殊符号

时间:2019-02-14 06:04:17

标签: android character-encoding android-webview

符号未进入android WebView

有关更多信息,请参见驱动器链接

https://drive.google.com/open?id=17PXFPJnVYkuGA_fkQPxskeIaw8AlzkcD

binding.tvQuestion.loadDataWithBaseURL("", questionlist.title, "text/html", "UTF-8", "");
binding.tvQuestion.getSettings().setJavaScriptEnabled(true);

如何显示特殊字符/ unicode字符?

1 个答案:

答案 0 :(得分:0)

尝试

在html文件中将正确的编码设置为元标记

<meta http-equiv="content-type" content="text/html; charset=UTF-8">

Android加载数据

webView.loadData("", "text/html; charset=utf-8", "UTF-8");

Android设置

WebSettings webSettings = webView.getSettings();
webSettings.setDefaultTextEncodingName("utf-8");  
webView.loadData("", "text/html; charset=utf-8", null);

如果无法使用,请替换特殊字符

mwebView.loadData(URLEncoder.encode(data, "utf-8").replaceAll("\\+"," "), "text/html", "utf-8");