android - Loading inline CSS in Android Webview problem
问题描述
I am developing an androind webview based application - the HTML, CSS and Javascript is built dynamically - I have done this before but have run into a insanely madding problem. when the css starts loading in webview it stops loading at the # color - The CSS build is as follows:
String h1 =
".sexy_line{\n" +
" display:block;\n" +
" border:none;\n" +
" color:transparent;\n" +
" height:6px;\n" +
" background:black;\n" +
" background: -webkit-gradient(radial, 50% 50%, 0, 50% 50%, 450, from(#2626ff), to(#ffffff00));\n" +
"}\n" +
".floatBottom\n" +
" {\n" +
" position: absolute; \n" +
" bottom: 0;\n" +
" }\n";
return h1;
}
it literally stops loading at:
background: -webkit-gradient(radial, 50% 50%, 0, 50% 50%, 450, from(
Environment:
Android: Tablet 7.1.1 Development Environment: Android Studio 3.5.3
Any help would be greatly appreciated --- Thank you
an update: i am loading the page with the following method:
wv = findViewById(R.id.idWebView);
settings.setDefaultTextEncodingName("utf-8");
wv.loadData(webInterface,"text/html","UTF-8");
解决方案
Was facing the same issue after I updated my target SDK.
Solved this by base64 encoding my HTML and then passing it base64
in encoding:
// instructions is the HTML string
webView.loadData(Base64.encodeToString(instructions.getBytes(), Base64.DEFAULT), "text/html", "base64");
Please check the blue box in the documentation, here: WebView.loadData
推荐阅读
- javascript - 在位掩码中打包和解包整数
- c++ - 如何提高BST的搜索操作效率?
- android - Android,在logcat中获取其他应用程序的所有事件?
- executorservice - 为 Completable 期货触发新的 Sleuth Tracer
- ios - 在 iPad 上使用 Swift UI 禁用拆分视图
- javascript - 使用 Fetch 发送 url 中的变量和 Body 中的对象
- r - 如何使用 R 在 .txt 文件中写入列表
- java - 如何延长课程两次?
- netlogo - 如何在 BehaviorSpace 中使用记者运行代码?
- javascript - Vuex - 调用异步函数