如何从另一个包在XML加载资源? [英] How to load resource from another package in xml?

查看:193
本文介绍了如何从另一个包在XML加载资源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道,存在是为了从另一个包code安装资源的XML文件这样的能力:

I know that exists ability to install resource xml file from another package in code like this:

String resourceName = getResources().getResourceEntryName(layoutResID);
String resourceTypeName = getResources().getResourceTypeName(layoutResID);
Resources skinResources = getResourcesForPackage("com.my.skin");
int skinResourceId = skinResources.getIdentifier(resourceName, resourceTypeName, "com.my.skin");
mLayoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mLayoutInflater.inflate(skinResources.getXml(skinResourceId), null);
super.setContentView(mLayoutInflater.inflate(skinResources.getXml(skinResourceId), null));

但我想知道如何使相同,但在XML和绘制资源:

But i would like to know how to make the same but in xml and for drawable resources:

例如:我有两个应用:

  • 在应用程序的与包的 com.my.main
  • 和应用的与包的 com.my.skin
  • application main with package "com.my.main"
  • and application skin with package "com.my.skin"

在安卓文档解释:

可能引用到另一个资源,形式   @ [+] [包:]类型:名称或在形式的主题属性   [包:] [类型:]名。

May be a reference to another resource, in the form "@[+][package:]type:name" or to a theme attribute in the form "?[package:][type:]name".

我试图说明是这样的:

安卓背景=@ com.my.skin:drawable:background_image

或者这样的:

安卓背景=?com.my.skin:drawable:background_image

但它不能正常工作,我的资源文件不编译。

but it not work, my resource file not compiled.

谁知道如何使用显式指定加载资源。

推荐答案

请您的项目库中的项目,你可以参考它在其他Android项目。

Make your project a library project and you can refer it in another android project.

库项目

这些项目包含可共享的Andr​​oid 源$ C ​​$ C 的资源,你可以在Android的项目引用。当你有要重用公共code这是很有用的。库项目不能安装到设备上,但是,它们在构建时被拉进的.apk文件。

These projects contain shareable Android source code and resources that you can reference in Android projects. This is useful when you have common code that you want to reuse. Library projects cannot be installed onto a device, however, they are pulled into the .apk file at build time.

有关详细信息,有主题下看一下链接的库项目。

For more information have a look at the link under the topic Library Projects.

http://developer.android.com/tool​​s/projects/index.html

您库项目将有勾选复选框,如图项目。

Your library project will have a check box ticked as shown in the project.

您可以添加库项目到你的Andr​​oid项目。右键单击您的项目。转到属性。在左侧面板上选择Android系统。

You can add library project to your android project. Right click on your project. Goto properties. Choose Android on the left panel.

这篇关于如何从另一个包在XML加载资源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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