Webview loadDataWithBaseURL不显示html android
尝试使用 loadData/loadDataWithBaseURL 渲染从 web 服务传递的 html 以在 webView 中显示。
我已经对 html 字符串 TextUtils.htmlEncode 进行了编码,并将其包装在 中。 <正文>但没有显示任何内容。
mMessageDetailsHtmlString = <html><body><div style="color:#ffffff" align="center"><h3>Test Promo</h3></div><p style="color:#ffffff">Here is some text about a great test promo.</p><p style="color:#ffffff"It includes an image (below) using a fully qualified URL<p><p style="color:#ffffff"><img href="http://myserver.com/media/images/img-logo.png" /></p><p style="color:#ffffff">This is a test message with white text</p></body></html>
//used loadDataWithBaseURL with a fake base url as loadData didn't work
mWebView.loadDataWithBaseURL("http://null", mMessageDetailsHtmlString, "text/html", "utf-8", null);
Trying to render html which is passed from a webservice to display in a webView using the loadData/loadDataWithBaseURL.
I've encoded the html string TextUtils.htmlEncode and wrapped it in <html> <body> but nothing is displayed.
mMessageDetailsHtmlString = <html><body><div style="color:#ffffff" align="center"><h3>Test Promo</h3></div><p style="color:#ffffff">Here is some text about a great test promo.</p><p style="color:#ffffff"It includes an image (below) using a fully qualified URL<p><p style="color:#ffffff"><img href="http://myserver.com/media/images/img-logo.png" /></p><p style="color:#ffffff">This is a test message with white text</p></body></html>
//used loadDataWithBaseURL with a fake base url as loadData didn't work
mWebView.loadDataWithBaseURL("http://null", mMessageDetailsHtmlString, "text/html", "utf-8", null);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来html中的文本是白色的,你的webview的背景也是白色的吗?
尝试
mWebView.setBackgroundColor(Color.BLUE);
Looks the text in that html is white, is your webview's background white too by any chance?
Try
mWebView.setBackgroundColor(Color.BLUE);