문제

I try to load images from resources (or assets):

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);

Resource and asset images are not displayed. What's wrong?

도움이 되었습니까?

해결책

If you use the LoadDataWithBaseUrl method instead it should work:

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

One way to simplify things is to also load the WebView from an HTML asset, which would allow you to just use relative paths for the images.

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

Also make sure to set the BuildAction on any asset file to AndroidAsset.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top