我正在webview上创建应用程序,webview在链接上加载本地html和样式
在Android 4-8上加载CSS,但在android 9上加载CSS
代码:
StringBuilder data = new StringBuilder();
data.append("<HTML><HEAD><LINK href=\"http://example.com/style.css\" type=\"text/css\" rel=\"stylesheet\"/></HEAD><body>");
data.append(bundle.getString("content"));
data.append("</body></HTML>");
webView.loadData(data.toString(), "text/html", "UTF-8");
答案 0 :(得分:1)
尝试添加清单
android:cleartextTrafficPermitted="true"
为此已通过android 9网络安全性。阅读:https://developer.android.com/training/articles/security-config
或
<application android:networkSecurityConfig="@xml/network_security_config">
network_security_config.xml
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true">
<trust-anchors>
<certificates src="system" />
</trust-anchors>
</base-config>
</network-security-config>