彻底解决Android WebView中文乱码的问题

WebView在显示中文时会出现乱码的问题,编码方式改为GBK或gb2312都不能解决问题。

Android 官方文档中对于加载HTML,给出了2中方法:

void loadData(String data, String mimeType, String encoding)
//Loads the given data into this WebView using a 'data' scheme URL.
void loadDataWithBaseURL(String baseUrl, String data, String mimeType, String encoding, String historyUrl)
//Loads the given data into this WebView, using baseUrl as the base URL for the content.

尝试的结果是:

第一种方法无论怎么改,中文都是乱码。

第二种方法至少这样用时,中文不是乱码。

webView.loadDataWithBaseURL(null,data, "text/html",  "utf-8", null);



发布了78 篇原创文章 · 获赞 54 · 访问量 30万+

猜你喜欢

转载自blog.csdn.net/chjr1000/article/details/50089047