加载一个Android资源到web视图 [英] Loading an Android resource into a webview

查看:179
本文介绍了加载一个Android资源到web视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Android应用程序,显示一本漫画书。为了使用内置变焦控制,我加载图片中,像这样一个web视图:

I have an Android app that displays a comic book. To make use of the built-in zoom controls, I am loading the pictures in a webview like so:

webView.loadUrl("file:///android_asset/page1.jpg");

这是工作得很好,但是,由于图像是在资产的文件夹,它们不是COM pressed这使我的apk巨大的。我想知道如何引用资源文件(从RES /绘制文件夹)与文件路径像我一样以上的资产。有谁知道这条道路是什么样子?我试着像文件:///res/drawable/pagetitle.jpg,但没有成功。感谢您的帮助。

This is working just fine, however, since the images are in the assets folder, they are not being compressed which makes my .apk enormous. I was wondering how to reference resource files (from the res/drawable folder) with a file path like I did above with the assets. Does anyone know what that path would look like? I've tried things like "file:///res/drawable/pagetitle.jpg" with no success. Thanks for the help.

更新:我发现这一点。文件:///android_res/drawable/page1.jpg是,我一直在寻找的路径

Update: I found that "file:///android_res/drawable/page1.jpg" was the path that I was looking for.

推荐答案

本网站

使用资源ID,格式是:

Using the resource id, the format is:

"android.resource://[package]/[res id]"

Uri path = Uri.parse("android.resource://com.androidbook.samplevideo/" + R.raw.myvideo);

,或使用资源子目录(型)和资源名称(文件名不带扩展名),格式为:

or, using the resource subdirectory (type) and resource name (filename without extension), the format is:

"android.resource://[package]/[res type]/[res name]"

Uri path = Uri.parse("android.resource://com.androidbook.samplevideo/raw/myvideo");

这篇关于加载一个Android资源到web视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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