用的WebView的loadData编码问题 [英] Encoding issue with WebView's loadData

查看:117
本文介绍了用的WebView的loadData编码问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是加载一些数据,包含Latin-1字符,在web视图

 字符串的uri = Uri.en code(HTML);
webview.loadData(URI,text / html的,ISO-8859-1);
 

在显示时,拉丁文字符被奇怪的字符替换。

如果我直接在一个TextView(只是为了测试),拉丁字符正确显示。加载HTML

任何人都可以帮忙吗?

感谢

HTML:

 < XML版本=1.0编码=ISO-8859-1&GT?;
!< D​​OCTYPE HTML PUBLIC -  // WAPFORUM // DTD XHTML 1.0移动// ENhttp://www.wapforum.org/DTD/xhtml-mobile10.dtd">
< HTML的xmlns =htt​​p://www.w3.org/1999/xhtml>

    <! - 一些HTML  - >

< / HTML>
 

解决方案

只有这样,有它的工作,作为评论的这里

  webview.loadDataWithBaseURL(假货://不是/必要,HTML,text / html的,UTF-8,);
 

没有URI编码,UTF-8 ... loadData错误?

I'm loading some data, containing latin-1 characters, in a WebView using

String uri = Uri.encode(html);
webview.loadData(uri, "text/html", "ISO-8859-1");

When displayed, the latin1 characters are replaced by weird characters.

If I load the html directly in a TextView (just to test), latin characters are properly displayed.

Anybody can help?

Thanks

html:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

    <!-- some html -->

</html>

解决方案

Only way to have it working, as commented here:

webview.loadDataWithBaseURL("fake://not/needed", html, "text/html", "utf-8", "");

No URI encoding, utf-8... loadData bug?

这篇关于用的WebView的loadData编码问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆