【发布时间】:2010-04-13 15:25:20
【问题描述】:
我将 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 中的图像?
【问题讨论】:
-
我找到了适合我的解决方案。我不知道如何从 /res/drawable 加载图像,但我可以将图像复制到 /assets 并通过 file:///android_asset/my_image.png 引用图像
-
所以我将 res/drawable/my_image.png 复制到 assets/my_image.png 然后使用