如何在Android中使用XML库引用的字符串从另一个包? [英] How to reference a string from another package in a library using XML in Android?

查看:946
本文介绍了如何在Android中使用XML库引用的字符串从另一个包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

而Android 文档告诉我,我可以访问

The Android documentation tells me that I can access a string from another package by using the "package name", whatever that means:

@[<package_name>:]<resource_type>/<resource_name>

所以在我的清单我要访问,我已经放在一个单独的库项目的字符串,在 com.globalmentor.android包 ---这就是我的研究类的,毕竟:

So in my manifest I want to access a string that I've placed in a separate library project, in the com.globalmentor.android package---that's where my R class is, after all:

    <activity
        android:label="@com.globalmentor.android:string/app_applicationlistactivity_label"
        android:name="com.globalmentor.android.app.ApplicationListActivity" >
    </activity>

这还不编译。但这:

That doesn't even compile. But this does:

    <activity
        android:label="@string/app_applicationlistactivity_label"
        android:name="com.globalmentor.android.app.ApplicationListActivity" >
    </activity>

为什么呢?什么是Android的文件意味着它谈到了包名?为什么不第一例的工作,为什么没有第二个例子中工作?我不希望我所有的资源名称合并到同一个研究文件---我希望他们分成包,就像我写了他们。

Why? What does the Android documentation mean which it talks about the "package_name"? Why doesn't the first example work, and why does the second example work? I don't want all my resource names merged into the same R file---I want them partitioned into packages, like I wrote them.

推荐答案

在短期:包名preFIX是共享库,而不是为你的apk

In short: package name prefix is for shared libraries, not for your apk.

该文件内容如下:

要引用系统的资源,你需要包括包名

To reference a system resource, you would need to include the package name

这相当于外部共享库(及其资源),您的应用程序链接反对(如地图)。他们拥有自己的研发类,而不是与你的应用程序的合并。

This corresponds for external shared libraries (and their resources), your application is linked against (e.g. maps). They have their own R class, not merged with that of your application.

这些都是你的Andr​​oid清单部分所提到的所有标准的Andr​​oid包和共享库。

These are all standard android packages and shared libraries you mentioned in section of android manifest.

由于尼古拉指出,所有的应用程序资源合并,这就是为什么大多数库项目使用prefixes像abs__他们的资源名称。

As Nikolay pointed out, all app resources are merged, that is why the majority library projects use prefixes like abs__ for their resource names.

请参阅库项目文档,了解更多信息。

See Library projects doc for additional info.

这篇关于如何在Android中使用XML库引用的字符串从另一个包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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