什么是“android:”前缀在android framework-res模块中的含义

时间:2012-01-13 03:31:35

标签: android android-resources android-framework

我从framework-res模块

中的styles.xml文件中复制此代码
<style name="Theme">

    <item name="colorForeground">@android:color/bright_foreground_dark</item>
    <item name="colorForegroundInverse">@android:color/bright_foreground_dark_inverse</item>
    <item name="colorBackground">@android:color/background_dark</item>
     

<style name="Theme.Black">
    <item name="android:windowBackground">@android:color/black</item>
    <item name="android:colorBackground">@android:color/black</item>
</style>

如您所见,它们都有一个属性名称,其值为windowBackground。但是formar有android:而后者没有。是否真的有必要在android框架中编写android:前缀?

2 个答案:

答案 0 :(得分:7)

发现这是一个有趣的问题,并尝试探索找到答案..这就是我发现的......

来自:http://developer.android.com/guide/topics/resources/style-resource.html

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style
        name="style_name"
        parent="@[package:]style/style_to_inherit">
        <item
            name="[package:]style_property_name"
            >style_value</item>
    </style>
</resources>

item - 为样式定义单个属性。必须是元素的子元素。 属性:     名称     属性资源。需要。 要定义的样式属性的名称,必要时带有包前缀(例如android:textColor)。

来自:http://developer.android.com/guide/topics/manifest/manifest-intro.html

资源价值 某些属性具有可以向用户显示的值 - 例如,活动的标签和图标。这些属性的值应该是本地化的,因此可以从资源或主题设置。资源值以下列格式表示,

@[package:]type:name

如果资源与应用程序位于同一个包中,则可以省略包名称,type是一种资源类型 - 例如“string”或“drawable” - 而name是标识特定资源的名称。例如: 来自主题的值以类似的方式表达,但带有初始“?”而不是'@':

?[package:]type:name

最后,我尝试给出没有android:的属性,并且它抛出了一个异常,虽然它编译成功。

答案 1 :(得分:1)

访问平台资源

Android包含许多标准资源,例如样式,主题和布局。要访问这些资源,请使用android软件包名称限定资源引用。例如,Android提供了一个布局资源,可用于ListAdapter

中的列表项
setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, myarray));

在此示例中,simple_list_item_1是平台为ListView中的项目定义的布局资源。您可以使用它而不是为列表项创建自己的布局。 (有关使用ListView的更多信息,请参阅列表视图教程。)