加载一个Android资源到web视图视图、加载、资源、Android

2023-09-12 02:55:51 作者:呆萌小迷糊

我有一个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");
 
精彩推荐
图片推荐