@Android 在 WebView 中显示/res/viewable [英] @Android display /res/viewable in WebView

查看:16
本文介绍了@Android 在 WebView 中显示/res/viewable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将 HTML 扔到 webview 进行渲染.在 HTML 中,我需要加载 /res/drawable 中的图像.

I am throwing HTML to a webview to render. In the HTML I need to load an image that I have in /res/drawable.

我有 /res/drawable/my_image.png 和这样的代码:

I have /res/drawable/my_image.png and code such as this:

final WebView browser = (WebView) findViewById(R.id.my_webview);
String html = new MyHelper(myObject).getHtml();
browser.loadDataWithBaseURL("", html, "text/html", "UTF-8", "");

其中字符串 html 类似于:

Where the String html has something like:

<html><head>
<h1>Here is the image</h1>
<img src="my_image.png" />
</head><html>

问题是,图像 src 属性应该是什么来引用 /res/drawable 中的图像?

The question is, what should that image src attribute be to refer to the image in /res/drawable?

推荐答案

这在 android 2.2 中有效

This worked in android 2.2

<img src = "file:///android_res/drawable/q1.png" />

其中 q1.png 在 res/drawable-hdpi 文件夹中

where q1.png is in the res/drawable-hdpi folder

这篇关于@Android 在 WebView 中显示/res/viewable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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