我將HTML投影到webview進行渲染。在HTML中,我需要加載我在/res/drawable
中的圖片。@Android顯示/ res /可在WebView中查看
我/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 – MikeNereson 2010-04-13 16:09:22
因此我複製了res/drawable/my_image。 png to assets/my_image.png然後使用 – MikeNereson 2010-04-13 16:09:54