如何加载HTML字符串中的WebView? [英] How to load html string in a webview?
问题描述
我有一个包含这样的HTML字符串:
i have a html string containing this:
<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=windows-1250">
<meta name="spanish press" content="spain, spanish newspaper, news,economy,politics,sports">
<title></title>
</head>
<body id="body">
<!-- The following code will render a clickable image ad in the page -->
<script src="http://www.myscript.com/a"></script>
</body>
</html>
我需要证明该网站将在Android的一个web视图。
I need to show that website into a webview in android.
我tryed这一切:
I tryed with all this:
webView.loadDataWithBaseURL(null, txt, "text/html", "UTF-8", null);
webView.loadDataWithBaseURL("x-data://base", txt, "text/html", "UTF-8", null);
webView.loadDataWithBaseURL("notreal/", txt, "text/htm", "utf-8",null);
另外我tryed删除DOCTYPE标签:
Also i tryed removing DOCTYPE tag:
TXT = txt.replace(!&LT; DOCTYPE HTML PUBLIC \ - // W3C // DTD HTML 4.01过渡// EN \&gt;中,);
那些没有人有工作。我只是实现显示的字符串到web视图(html的code),但不包含必须与HTML code创建的网站。
No one of those have work. I just achieved to show the string into the webview (the html code), but not the website that must be created with that html code.
什么是错的?
推荐答案
要加载的WebView数据。调用loadData()的WebView方法
To load your data in WebView. Call loadData() method of WebView
wv.loadData(yourData, "text/html", "UTF-8");
您可以检查这个例子
<一个href="http://developer.android.com/reference/android/webkit/WebView.html">http://developer.android.com/reference/android/webkit/WebView.html
您应该添加 - \ - 前 - - 例如 - > 名= \西班牙preSS \
You should add -- \ -- before -- " -- for example --> name=\"spanish press\"
以下字符串为我工作。
String webData = "<!DOCTYPE html><head> <meta http-equiv=\"Content-Type\" " +
"content=\"text/html; charset=utf-8\"> <html><head><meta http-equiv=\"content-type\" content=\"text/html; charset=windows-1250\">"+
"<meta name=\"spanish press\" content=\"spain, spanish newspaper, news,economy,politics,sports\"><title></title></head><body id=\"body\">"+
"<script src=\"http://www.myscript.com/a\"></script>şlkasşldkasşdksaşdkaşskdşk</body></html>";
这篇关于如何加载HTML字符串中的WebView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!