WebView.loadData 不适用于 Android 9.0 (API-29) [英] WebView.loadData not working on Android 9.0 (API-29)

查看:29
本文介绍了WebView.loadData 不适用于 Android 9.0 (API-29)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文章应用程序,我在 WebView 中显示文章.在 Android 9.0 (API-29) 版本中,此 WebView 不起作用.该应用在我的文章活动中显示NOTHING.

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

因此我的解决方案是:

mWebview.loadDataWithBaseURL(null,htmlContent,"text/html", "utf-8", null);

这篇关于WebView.loadData 不适用于 Android 9.0 (API-29)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆