【发布时间】:2018-07-16 11:47:02
【问题描述】:
我正在使用 InjectCSS 脚本在 webview 上使用额外的 css 文件。 但是脚本从 assets 文件夹中获取 CSS 文件,我希望 css 文件在外部托管。
private void injectCSS() {
try {
InputStream inputStream = getAssets().open("style.css");
byte[] buffer = new byte[inputStream.available()];
inputStream.read(buffer);
inputStream.close();
String encoded = Base64.encodeToString(buffer, Base64.NO_WRAP);
wv.loadUrl("javascript:(function() {" +
"var parent = document.getElementsByTagName('head').item(0);" +
"var style = document.createElement('style');" +
"style.type = 'text/css';" +
// Tell the browser to BASE64-decode the string into your script !!!
"style.innerHTML = window.atob('" + encoded + "');" +
"parent.appendChild(style)" +
"})();");
} catch (Exception e) {
e.printStackTrace();
}
}
我尝试将输入流更改为 url,但没有成功。
InputStream inputSteam = new URL("http://www.website.com/folder/style.css").openStream();
【问题讨论】:
-
有人可以帮助我吗?
标签: android css webview inputstream inject