1

I've searched but all I can find was making it into a website with the content as the image. Isn't there any direct way to load an image from the drawable folder in to a webview? Thanks in advance.

Lendl Leyba
  • 2,287
  • 3
  • 34
  • 49
  • refer this answer this may help you to solve it.. [Android add image to webview from a drawable](http://stackoverflow.com/questions/4534043/android-add-image-to-webview-from-a-drawable) – Pragnesh Ghoda シ Jun 10 '14 at 10:09
  • You can't load image from drawables however why not you try loading from assets. – Ahmed Nawaz Jun 10 '14 at 10:11
  • Possible duplicate of [@Android display /res/viewable in WebView](http://stackoverflow.com/questions/2630829/android-display-res-viewable-in-webview) – rds Jun 23 '16 at 14:38

2 Answers2

2

this link : Android add image to webview from a drawable

You can only do such a thing if our image is inside your /assets folder. Also, you must load your html with a baseUrl that's inside your assets folder.

You can use WebView.loadUrl() or WebView.loadDataWithBaseURL():

webView.loadUrl("file:///android_asset/file.html");

or

webView.loadDataWithBaseURL("file:///android_asset/", "", "text/html", "utf-8", null);

(file.jpg should be inside your assets folder)

Too , see this link:

how to load a picture from my resource in webview?

Android: how to retrieve an image from res/drawable and put it into WebView.loadUrl()

Community
  • 1
  • 1
Saeid
  • 2,261
  • 4
  • 27
  • 59
2

I have found this answer from other post and it works for me by which we can load resource from drawable also.

web_object.loadDataWithBaseURL("file:///android_res/drawable/", "<img src='test.jpg' />", "text/html", "utf-8", null);
Manmohan Badaya
  • 2,326
  • 1
  • 22
  • 35