我有一个包含这样的HTML字符串:如何在webview中加载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>
我需要到该网站显示成Android的网页视图。
我tryed这一切:
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标签:
txt=txt.replace("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">", "");
那些没有人有工作。我刚刚实现将字符串显示到webview(html代码)中,但不是必须使用该html代码创建的网站。
出了什么问题?
读你尝试'loadData'? – njzk2
你可以把这个html字符串放在res/values/strings.xml文件中,然后用例如'你的html这里创建的项目 '然后通过'Html.fromHtml(getString(R.string .website))',请检查它是否有一些时间,因为我想知道它是否也可以工作;) –
deadfish
(无论如何,你需要基础url?) – njzk2