我想在android中的webview中显示html数据,如下所示。
我将我的背景图像放在drawable-hdpi文件夹中,我给出了如下路径。但它没有受到影响。
String strBody="<html><body>";
for (int i = 0; i < dslist.size(); i++) {
if(dslist.get(i).getFrom().equals("inbox"))
{
strBody += "<div style='word-break:break-all;background-image:url('../res/drawable-hdpi/msgblue_box.png');width:60%; ;padding:20px;margin:2%'>" + dslist.get(i).getBody()+"</br>"+dslist.get(i).getDateformat()+ "</div>";
}
else
{
strBody += "<div style='background-image:url('../res/drawable-hdpi/msgblue_box.png');width:60%;margin:2%;margin-left:30%;padding:20px;'>" +dslist.get(i).getBody()+"</br>"+dslist.get(i).getDateformat()+ "</div>";
}
}
strBody+= "<br /> <br /></body></html>";
webview.loadDataWithBaseURL(null, strBody, null, "utf-8", null);][1]
答案 0 :(得分:1)
将此图像放入“资源文件夹”并尝试这种方式
String strBody="<html><body>";
for (int i = 0; i < dslist.size(); i++) {
if(dslist.get(i).getFrom().equals("inbox"))
{
strBody += "<div style='word-break:break-all;background-image:url(file:///android_asset/msgblue_box.png);width:60%; ;padding:20px;margin:2%'>" + dslist.get(i).getBody()+"</br>"+dslist.get(i).getDateformat()+ "</div>";
}
else
{
strBody += "<div style='background-image:url(file:///android_asset/msgblue_box.png);width:60%;margin:2%;margin-left:30%;padding:20px;'>" +dslist.get(i).getBody()+"</br>"+dslist.get(i).getDateformat()+ "</div>";
}
}
strBody+= "<br /> <br /></body></html>";
webview.loadDataWithBaseURL(null, strBody, null, "utf-8", null);][1]