如何将可绘制文件夹中的图像放在HTML文件中

时间:2012-04-18 08:17:32

标签: android

我的/res/raw/test.html

中有一个HTML文件

我使用以下代码在网页视图中显示

WebView wbview = (WebView)findViewById(R.id.webView1);
InputStream fin;
    try
    {
        fin = getResources().openRawResource(R.raw.manual);
        byte[] buffer = new byte[fin.available()];
        fin.read(buffer);
        fin.close();
        wbview.loadData(new String(buffer), "text/html", "UTF-8");
    }
    catch (IOException e)
    {
        e.printStackTrace();
    }

这是我的HTML文件代码

<html>
    <p>
    Lorem ipsum dolor sit amet,
    </p>
  <table>
   <tr>
         <td>
       <img src=\\"file:///android_asset/test_image2.jpg\"/>    
           <img src="test_image2.jpg" width="50px" alt="Hi">

       <img src=\"res/drawable/test_image.png"/>
       <img src="file:///android_res/drawable/test_image.png" />
       <img src=\"file:///android_res/drawable/test_image.png"\ />
         </td>
   </tr>
</table>
</html>

我想在我的html文件中显示资源文件夹中的图像... 我尝试了所有可能性仍然不起作用。它只显示一个HTML文本,但对于一个图像,我不知道如何显示它

请帮帮我

1 个答案:

答案 0 :(得分:16)

您可以从android资源文件夹加载html页面,如下面的代码。

WebView webView = new WebView(this);
webView.loadUrl("file:///android_asset/manual.html");
setContentView(webView);

你也需要在下面制作你的html。

 <html>
  <p>
   Lorem ipsum dolor sit amet,
  </p>
<table>
  <tr>
      <td>
     <img src="file:///android_asset/test_image2.jpg"/>    
      <img src="file:///android_asset/test_image2.jpg" width="50px" alt="Hi">
     <img src="file:///android_res/drawable/test_image.png"/>
     <img src="file:///android_res/drawable/test_image.png" />
     <img src="file:///android_res/drawable/test_image.png" />
        </td>
      </tr>
    </table>
  </html>