WebView:从资源(或资产)加载图像

时间:2012-01-10 18:25:18

标签: android-webview xamarin.android

我尝试从资源(或资源)加载图片:

String summary = "<html><body>Hello, images!" +
   "<br/>res: <img src='file:///android_res/drawable/icon.png'/>" +
   "<br/>asset: <img src='file:///android_asset/Icon.png'/>" +
   "<br/>www: <img src='http://www.droiddraw.org/droidraw-small.png'></body></html>";
web_view.LoadData(summary, "text/html", null);

不显示资源和资产图像。怎么了?

1 个答案:

答案 0 :(得分:2)

如果您使用LoadDataWithBaseUrl方法,则应该有效:

webView.LoadDataWithBaseURL(null, summary, "text/html", null, null);

简化操作的一种方法是从HTML资源加载WebView,这样您就可以只使用图像的相对路径。

webView.LoadUrl("file:///android_asset/summary.html");

还要确保将任何资产文件上的BuildAction设置为AndroidAsset。

相关问题