我的/res/raw/test.html中有一个HTML文件
并使用以下代码在Web视图中显示它
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();
}
Run Code Online (Sandbox Code Playgroud)
这是我的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>
Run Code Online (Sandbox Code Playgroud)
我想在我的html文件中显示我的资源文件夹中的图像...我尝试了所有可能性仍然无法正常工作.它只显示一个HTML文本,但对于一个图像,我不知道如何显示它
请帮我
Her*_*rry 16
您可以从android资源文件夹加载您的html页面,如下面的代码.
WebView webView = new WebView(this);
webView.loadUrl("file:///android_asset/manual.html");
setContentView(webView);
Run Code Online (Sandbox Code Playgroud)
而且你需要在下面制作你的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>
Run Code Online (Sandbox Code Playgroud)