如何引用本地css文件在Android开发一个静态的web视图窗口?视图、静态、窗口、文件

2023-09-03 20:51:22 作者:美男子

我已经创建了一个静态的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\">";