Android - webview 中的本地图像 [英] Android - local image in webview

查看:48
本文介绍了Android - webview 中的本地图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的网络视图中显示本地图像:

I'm trying to diplay a local image in my webview :

 String data = "<body>" + "<img src="file:///android_asset/large_image.png"/></body>";
 webview.loadData(data, "text/html", "UTF-8");

此代码不显示任何内容,而是:

This code doesn't display anything, instead of :

 webview.loadUrl("file:///android_asset/large_image.jpg");

这个可行,但我需要复杂的网页,而不仅仅是一张图片.

This one works, but I need to have complex web page, not just a picture.

有什么想法吗?

推荐答案

在 Webview 中加载 Html 文件并将图像放入资产文件夹并使用 Html 读取该图像文件.

Load Html file in Webview and put your image in asset folder and read that image file using Html.

<html>
  <table>
    <tr>
      <td>
        <img src="abc.gif" width="50px" alt="Hello">
      </td>
    </tr>
  </table>
</html>

现在在 Webview 中加载该 Html 文件

Now Load that Html file in Webview

webview.loadUrl("file:///android_asset/abc.html");  

这篇关于Android - webview 中的本地图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆