我将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文件夹中