什么是使用RES /价值/ public.xml在Android上的文件? [英] What is the use of the res/values/public.xml file on Android?

查看:339
本文介绍了什么是使用RES /价值/ public.xml在Android上的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我搜索谷歌,但未能找到任何相关的结果。

I've searched on Google, but couldn't find any relevant results.

我还检查 Android官方文档,然后 此页 (所有可用资源)是所有我能找到。在相关链接(到 RES /价值/ 目录下),我发现这个网页是:

I also checked the official Android docs and this page (for all the available resources) was all I could find. The relevant links (to the res/values/ directory) I found on this page were:

  • string resources
  • style resources
  • more resources

这些页面不告诉在 RES /价值/ public.xml 文件什么。
下面是一个示例我发现 这种类型的文件

These pages don't tell anything about the res/values/public.xml file.
Here is an example I found for this type of file.

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <public type="attr" name="commentTextColor" id="0xAA010007" />
    <public type="drawable" name="add_icon_bl" id="0xAA020000" />
    <public type="layout" name="act_date_picker" id="0xAA030001" />
    <public type="anim" name="activity_slide_from_bottom" id="0xAA040000" />
    <public type="xml" name="pref_menu" id="0xAA050000" />
    <public type="raw" name="alert_bell_animation_bl" id="0xAA060000" />
    <public type="array" name="taskRepeat" id="0xAA070000" />
    <public type="color" name="theme_main_color_bl" id="0xAA080000" />
    <public type="string" name="no_internet" id="0xAA0a0001" />
    <public type="id" name="page1" id="0xAA0d0015" />
</resources>

正如你可以在 键入 属性,它包含pretty的多少<​​STRONG>所有标准的资源类型您通常放在单独的目录 RES 目录...

As you can see from the type attribute, it contains pretty much all the standard resource types that you normally put in separate directories under the res directory...

为什么总会有想滥用了Android提供的目录,并使用一个单独的文件来存储所有的值?有人可以给更多有关这个?

推荐答案

该文件的 RES /价值/ public.xml 用于分配固定的资源ID到Android资源。

The file res/values/public.xml is used to assign fixed resource IDs to Android resources.

考虑的 RES /值这些组字符串资源/ strings.xml中

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="string1">String 1</string>
    <string name="string3">String 3</string>
</resources>

Android的资产打包工具(AAPT)可以分配这些资源下列资源ID应用程序编译时:

The Android Asset Packaging Tool (aapt) might assign the following resource IDs for these resources when the app is compiled:

public final class R {
    // ...
    public static final class string {
        public static final int string1=0x7f040000;
        public static final int string3=0x7f040001;
    }
}

现在,更改设置字符串资源,

Now, change the set of string resources to

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="string1">String 1</string>
    <string name="string2">String 2</string>
    <string name="string3">String 3</string>
</resources>

,你会发现,对于 @字符串/ STRING3 资源ID发生了改变:

and you'll notice that the resource ID for @string/string3 has changed:

public final class R {
    // ...
    public static final class string {
        public static final int string1=0x7f040000;
        public static final int string2=0x7f040001;
        public static final int string3=0x7f040002; // New ID! Was 0x7f040001
    }
}

要prevent这一点,你可以使用 RES /价值/ public.xml

To prevent this, you can use res/values/public.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <public type="string" name="string3" id="0x7f040001" />
</resources>

,这将导致在被分配的资源ID如下:

which will result in the resource IDs being assigned as follows:

public final class R {
    // ...
    public static final class string {
        public static final int string1=0x7f040000;
        public static final int string2=0x7f040002;
        public static final int string3=0x7f040001; // Resource ID from public.xml
    }
}

应用程序很少有 RES /值的任何使用/ public.xml ,因为分配到的资源的资源标识没有关系。当他们改变,整个应用程序无论如何重建使资源通过资源ID在Java中code的任何引用将被更新。

Applications rarely have any use for res/values/public.xml since the resource IDs assigned to resources does not matter. When they change, the entire application is rebuilt anyway so any references in Java code to resources by resource ID will be updated.

RES /值最显著用户/ public.xml 是Android平台本身。内置迎战老版本的Andr​​oid应用程序假定某种资源有一定的资源ID。例如,在Android资源<一href="http://developer.android.com/reference/android/R.style.html#Theme"><$c$c>@android:style/Theme必须有资源ID 0x01030005为平台,带有内置迎战老版本的平台的应用程序向后兼容。

The most significant user of res/values/public.xml is the Android platform itself. Applications built against old versions of Android assumes that certain resource have a certain resource ID. For example, the Android resource @android:style/Theme must always have the resource ID 0x01030005 for the platform to be backwards compatible with apps built against old versions of the platform.

如果你好奇的资源ID如何分配,请参考这个答案的更多细节:<一href="http://stackoverflow.com/questions/6517151/how-does-the-mapping-between-android-resources-and-resources-id-work/6646113#6646113">How做Android的资源和资源ID工作之间的映射?

If you are curious about more details on how resource IDs are assigned, please refer to this answer: How does the mapping between android resources and resources ID work?

这篇关于什么是使用RES /价值/ public.xml在Android上的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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