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.
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()
我从其他帖子中找到了这个答案,它对我有用,我们也可以通过它从drawable加载资源。
web_object.loadDataWithBaseURL("file:///android_res/drawable/", "<img src='test.jpg' />", "text/html", "utf-8", null);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.