首页 > 解决方案 > 特殊符号未在 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 字符?

标签: androidcharacter-encodingandroid-webview

解决方案


尝试

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

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

Android 加载数据

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

安卓设置

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");

推荐阅读