【发布时间】:2015-07-05 22:02:53
【问题描述】:
我想在 Webview 中显示 html 字符串的内容,并使用 css 文件调整图像大小并更改字体系列。
我将一个名为style.css 的css 文件放在assets/CSS/ 文件夹中。
我试图将此文件添加到我的html字符串data[3]。
StringBuilder sb = new StringBuilder();
sb.append("<html>" +
"<head>" +
"<link href=\"style.css\" type=\"text/css\" rel=\"stylesheet\"/>" +
"</head>" +
"<body>");
sb.append(data[3]);
sb.append("</body>" +
"</html>");
webView.loadDataWithBaseURL("file://android_asset/",sb.toString(),"text/html","UTF-8","");
在我的 css 文件中,我有这个:
img {
width : 100%;
height : auto;
}
div {
font-family : "Times New Roman";
}
但我不明白为什么 css 文件不起作用。
当我显示我的 html 代码时,它看起来不错:<html><head><link href="style.css" type="text/css" rel="stylesheet"/></head><body><p style="text-align: justify;">Je souhaite aujourd’hui vous faire un retour sur mon dernier Trail en date avec mes petites nouvelles, les Spyridon MR de VFF.</p>
我错过了什么吗?
请帮帮我,我什么都试过了。
【问题讨论】:
-
该位置是否存在 CSS 文件,但似乎不影响 html 元素或文件是否引发 404 错误?
-
没有错误,文件存在于app/src/main/assets/CSS中
-
在您的示例中,您将字体更改应用于 div,但您的 html 示例中没有 div。也没有图像。相对于您的 html 文件,style.css 的位置是否正确?
-
'app/src/main/assets/CSS'。您没有在 html 或 baseurl 参数中提及子文件夹 CSS。首先尝试不使用该文件夹。
-
'sb.append(data[3]);'。 ???请解释该语句应该做什么。