6

我从 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。但是形式有 aandroid:而后者没有。真的有必要android:在android框架中写前缀吗?

4

2 回答 2

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 - 定义样式的单个属性。必须是元素的子元素。attributes: name 属性资源。必需的。要定义的样式属性的名称,必要时带有包前缀(例如 android:textColor)。

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

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

@[package:]type:name

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

?[package:]type:name

最后,我尝试在没有 android: 的情况下提供属性,尽管编译成功,但它引发了异常。

于 2012-01-13T04:20:29.563 回答
1

访问平台资源

Android 包含许多标准资源,例如样式、主题和布局。要访问这些资源,请使用 android 包名称限定您的资源引用。例如,Android 提供了一个布局资源,您可以将其用于 a 中的列表项ListAdapter

setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, myarray));

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

于 2012-01-13T05:03:44.873 回答