我想知道如何在 webview 中显示带有相对/本地镜像引用的 HTML 页面。目标是让 html 页面和所有链接的图像包含在 android 应用程序包本身中。
我需要在哪里放置 Assets ( Assets 目录?)以及如何引用这些 Assets 以便它们加载到 WebView 中?
谢谢! 斯文
最佳答案
你可以把所有的html和图片放到assets目录下,比如:
assets\html\
index.html
image1.png
image2.jpg
html 文件中所有对图像的引用都应采用 file://url 的形式
<html>
<body>
<img src="file:///android_asset/html/image1.png">
<img src="file:///android_asset/html/image2.jpg">
</body>
</html>
毕竟,只需照常将此 HTML 加载到 WebView 即可:
webView.loadUrl("file:///android_asset/html/index.html");
关于android - 将包 html + 资源加载到 webview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2994911/