我有一个包含以下内容的 HTML 字符串:
<!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>
我需要在安卓应用中将网站显示在Webview中。
我尝试了以下所有方法:
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);
我也试过移除 DOCTYPE 标签:
txt=txt.replace("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">", "");
但都没有生效。我只能在 WebView 中显示字符串(HTML 代码),而不能显示由该 HTML 代码创建的网站。
出了什么问题?
loadData
吗? - njzk2<string name="website">your html here</string>
,然后通过Html.fromHtml(getString(R.string.website))
来加载它。如果你有时间,请检查一下它是否有效,因为我也想知道它是否可行 ;) - deadfish