如何引用的资产在库项目 [英] how to reference an asset in a library project

查看:114
本文介绍了如何引用的资产在库项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在属于的项目,我叫一个类:

In a class belonging to a Library project I call:

webview.loadUrl("file:///android_asset/info.html", null);

不幸的是,这只是工作,如果我的复制文件info.html里进的应用程序的的项目资产的文件夹中。

Unfortunately, this only works if I duplicate the file info.html into the Application's project asset folder as well.

有没有办法告诉一个Android库code:看在图书馆的资源文件夹中文件,不可以在应用程序的资产文件夹

Is there a way to tell an Android library code: "look for this file in the library's assets folder, not in the application's assets folder" ?

推荐答案

Android的文档

库项目不能包含原始资产

该工具不支持在库项目中使用的原材料资源文件(保存在资产/目录)。由应用程序使用任何资产资源必须被存储在应用项目本身的资产/目录。然而,保存在res /目录资源文件都支持。

The tools do not support the use of raw asset files (saved in the assets/ directory) in a library project. Any asset resources used by an application must be stored in the assets/ directory of the application project itself. However, resource files saved in the res/ directory are supported.

如果你想包括一个图书馆项目文件,你需要把它的资源而不是资产。如果你想从你的库项目加载HTML文件到一个web视图,这意味着你必须去比通常的资产URL更迂回的方法。相反,你将不得不读取资源数据,并使用类似<一个href="http://developer.android.com/reference/android/webkit/WebView.html#loadData%28java.lang.String,%20java.lang.String,%20java.lang.String%29">loadData.

If you want to include files from a Library project, you'll need to put it in the resources instead of the assets. If you're trying to load HTML files from your library project into a WebView, this means that you'll have to go a more roundabout method than the usual asset URL. Instead you'll have to read the resource data and use something like loadData.

这篇关于如何引用的资产在库项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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