如何引用本地css文件在Android开发一个静态的web视图窗口? [英] How to reference local css files in a static webview window in android dev?
本文介绍了如何引用本地css文件在Android开发一个静态的web视图窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经创建了一个静态的HTML页面将显示在web视图,我已经在 /assets/common.css
文件夹内的css文件。在code样子;
I've created a static html page to be displayed in the WebView, I've a css file inside the /assets/common.css
folder. The code looks like;
String linkCss = "<link rel=\"stylesheet\" href=\"/assets/common.css\" type=\"text/css\">";
String body = "<html><header>" + linkCss + "</header>" + content + "</body></html>";
webViewer.loadDataWithBaseURL("x-data://base", body , "text/html", "UTF-8", null);
除了正确的CSS没有被应用
一切都显示。什么问题?
Everything display correctly except the CSS isn't being applied. Whats the problem?
推荐答案
我想,你也应该替换 /assets/common.css
与文件:///android_asset/common.css
在CSS链接。试试这个
I think, you should also replace the /assets/common.css
with file:///android_asset/common.css
in the css link. Try this
String linkCss = "<link rel=\"stylesheet\" href=\"file:///android_asset/common.css\" type=\"text/css\">";
这篇关于如何引用本地css文件在Android开发一个静态的web视图窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文