WebView.loadData无法在Android 9.0(API-29)上运行 [英] WebView.loadData not working on Android 9.0 (API-29)
本文介绍了WebView.loadData无法在Android 9.0(API-29)上运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个文章应用,我正在WebView
中显示文章.在Android版本9.0(API-29)中,此WebView
不起作用.该应用程序在我的文章活动"中显示没有内容.
I have an article app, I am showing articles in WebView
. In Android version 9.0 (API-29) this WebView
is not working. The app shows NOTHING in my article Activity.
mWebView.setVisibility(View.VISIBLE);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setLoadWithOverviewMode(true);
mWebView.getSettings().setUseWideViewPort(true);
mWebView.getSettings().setMinimumFontSize(14);
String htmlContent = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"
+ "<head>"
+ "<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\" />"
+ "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"/>"
+ "<style type=\"text/css\">body{color: #525252;} img {max-width: 100%; height: auto}</style>"
+ "</head>"
+ item.getContent() //content of item
+ "";
mWebView.loadData(htmlContent, "text/html; charset=utf-8", "UTF-8");
结果,我该如何解决这个问题?
As a result, how can I solve this problem?
推荐答案
我解决了我的问题,该问题发生在具有最新Chrome的智能手机中.
I solved my problem, the problem occurs in Smartphones that has latest Chrome.
解决方案:
请勿使用
mWebview.loadData
方法,而不是使用
mWebview.loadDataWithBaseURL
结果,我的解决方法是:
As a result my solution is:
mWebview.loadDataWithBaseURL(null,htmlContent,"text/html", "utf-8", null);
这篇关于WebView.loadData无法在Android 9.0(API-29)上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文