我们想在 webview 中离线(没有互联网连接)显示 html 页面及其内容,如文本、图像等。我们只能显示文本。对于图像,我们将图像从图像 url 存储在内部存储(sd 卡)上,并将该图像 url(服务器 url)替换为图像内部存储(sd 卡)路径。
但是,这些图像没有显示在 WebView 中。
例如, 下面是html中的img标签..
<img alt="img" class="center_top_img" src="http://test.com/uploads/section/images/523.jpg" />
我们正在用图像内部存储(sd 卡)路径替换上面的图像 url(服务器 url)
<img alt="img" class="center_top_img" src=\"file:///data/data/com.app.test/files/523.jpg\" />
最佳答案
无论图片在哪里,只要获取它的绝对路径,并提前加上“file://”就可以了。
File file = ...
String imagePath + "file://" + file.getAbsolutePath();
String html = "...<img src=\""+ imagePath + "\">...";
关于android - 如何从android中的webview中的内部存储加载图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34433136/