显示在WebView中imges静态html [英] Show static html with imges in WebView

查看:104
本文介绍了显示在WebView中imges静态html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些问题,显示出静态的html文件,图像外(店作为资产),例如 About.html

I've some problem with showing static html file with extra images (store as assets), for example About.html.

<html>
 <body>
  <div style="text-align:center;">
   <p>Some text in utf-8</p>
   <img src="image.png"/>
  </div>
 <body>
<html>

在第一个方法我试过,以显示我的内容为:

In first approach I've tried to display my content as:

webView.loadUrl("file:///android_asset/About.html");

和几乎一切工作正常。我看到的形象和我的字符串,但不是UTF-8。经过一番研究,我试图加载我的HTML以另一种方式:

and almost everything worked ok. I saw image and my string, but not in utf-8. After some research I've tried to load my html in another way:

webView.loadDataWithBaseURL(null, dataContent, "text/html", "utf-8", null);  

之后的字符串是正确psented $ P $,但我不能够显示图像。它看起来像web视图无法从资产文件夹加载图像。你有我怎么能显示静态HTML内容有任何建议(UTF-8 +图像)?

After that strings are presented correctly, but I'm not be able to display images. It looks like webView are not able to load image from assets folder. Do you have any suggestions how can I display static html content (utf-8 + images)?

推荐答案

当您使用loadDataWithBaseURL的方法,你必须设置基本URL。你的情况,这将是资产的文件夹。所以,试试这个:

When you use the "loadDataWithBaseURL" method you have to set the base URL. In your case it would be the Asset-Folder. So, try this:

    webView.loadDataWithBaseURL("file:///android_asset/", dataContent, "text/html", "utf-8", null);

在我的测试文本和图像正确加载。
看看这个问题也是:<一href=\"http://stackoverflow.com/questions/11754288/using-webviews-loaddatawithbaseurl-not-loading-images-from-sdcard\">Using的WebView loadDataWithBaseURL不加载SD卡从

In my test the text and the image was loaded correctly. Have a look at this question also: Using webView's loadDataWithBaseURL not loading images from sdcard

这篇关于显示在WebView中imges静态html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆