Android的web视图loadDataWithBaseURL从资产如何载入图像? [英] Android webview loadDataWithBaseURL how load images from assets?
本文介绍了Android的web视图loadDataWithBaseURL从资产如何载入图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的项目,我有一个文件:
In my project I have a files:
"MyProject/assets/folder1/image1.jpg"
"MyProject/assets/folder1/index.html".
在web视图我需要打开index.html的(带照片)。
In webView I need to open index.html (with images).
我想这code:
String baseUrl = "file:///android_asset/folder1/";
webView.loadDataWithBaseURL(baseUrl, readFileAsString("index.html") , mimeType, "UTF-8", null);
但图像不加载。
But images don't loading.
如果我把图像资产目录( MyProject的/资产/
),并的baseUrl =文件:/// android_asset
图像正确加载;
If I put images to "assets" directory (MyProject/assets/
) and make baseUrl = "file:///android_asset"
images are loaded correctly;
如何加载图像不仅是从根目录下的资产,但是从资产/文件夹1
?
How load images not only from root assets directory, but and from assets/folder1
?
推荐答案
试试这样
WebView webview = (WebView)this.findViewById(R.id.webview);
String html = "<html><head><title>TITLE!!!</title></head>";
html += "<body><h1>Image?</h1><img src="icon.png" /></body></html>";
webview.loadDataWithBaseURL("file:///android_res/drawable/", html, "text/html", "UTF-8", null);
有关详细信息,请尝试
For more information try this link
这篇关于Android的web视图loadDataWithBaseURL从资产如何载入图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文