我将HTML转换到webview进行渲染。在HTML中,我需要加载/res/drawable中的图像。

我有/res/drawable/my_image.png和这样的代码:

final WebView browser = (WebView) findViewById(R.id.my_webview);
String html = new MyHelper(myObject).getHtml();
browser.loadDataWithBaseURL("", html, "text/html", "UTF-8", "");

其中,字符串html具有类似以下内容:
<html><head>
<h1>Here is the image</h1>
<img src="my_image.png" />
</head><html>

问题是,该图像src属性应该引用/res/drawable中的图像吗?

最佳答案

这在Android 2.2中工作

<img src = "file:///android_res/drawable/q1.png" />

其中q1.png在res/drawable-hdpi文件夹中

10-07 19:28
查看更多