将 Android 资源加载到 WebView 中
我有一个显示漫画书的 Android 应用程序。为了使用内置缩放控件,我将图片加载到 < code>WebView 像这样:
webView.loadUrl("file:///android_asset/page1.jpg");
这工作得很好,但是,由于图像位于资产文件夹中,它们没有被压缩,这使得我的 .apk 巨大。我想知道如何使用文件路径引用资源文件(来自 res/drawable
文件夹),就像我上面对资产所做的那样。有谁知道那条路会是什么样子?我尝试过类似 "file:///res/drawable/pagetitle.jpg"
但没有成功。感谢您的帮助。
更新:
我发现“file:///android_res/drawable/page1.jpg”
是我正在寻找的路径。
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");
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.
Update:
I found that "file:///android_res/drawable/page1.jpg"
was the path that I was looking for.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
来自 此站点
使用资源 ID,格式为:
或者,使用资源子目录(类型)和资源名称(不带扩展名的文件名),格式为:
from this site
Using the resource id, the format is:
or, using the resource subdirectory (type) and resource name (filename without extension), the format is:
我还必须使用
loadDataWithBaseURL
而不是简单的loadData
才能使file:///android_res/drawable/page1.jpg
正常工作。I also had to use
loadDataWithBaseURL
instead of just plainloadData
to get thefile:///android_res/drawable/page1.jpg
to work.