为什么以及何时我们需要添加 android: 样式前缀?
Why and when we need to add android: prefix to style?
I have seen that some Style attributes require android
prefix and some don't need it. What is the reason. like
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
为什么我们没有使用 android:windowActionBar
和 android:windowNoTitle
基于 SDK 版本 Android 样式分组在不同的命名空间中。为了覆盖主题,您必须遵循它的命名空间。
这就是扩展 AppCompat
主题时不需要 android:
前缀的原因,但如果您想要其他东西,假设 Theme.Holo
- 您有 2它们的不同样式 - 一种用于 Lollipop 之前的设备,一种用于 -21
,后者在每个样式属性前都有 android:
前缀。
这取决于您使用的主题及其上下文。这些属性由不同的来源定义。
如果属性名称以 android:
为前缀,则它是一个框架属性,只能用于定义了它的 Android 版本。
如果属性根本没有前缀,则属性由您自己的应用程序定义。这包括您使用库引入的所有属性定义。
在您的示例中,您为 AppCompat
定义了一个主题,它是支持库的一部分,因此也是您的应用程序的一部分。框架小部件不会直接识别这些颜色。
I have seen that some Style attributes require
android
prefix and some don't need it. What is the reason. like
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
为什么我们没有使用 android:windowActionBar
和 android:windowNoTitle
基于 SDK 版本 Android 样式分组在不同的命名空间中。为了覆盖主题,您必须遵循它的命名空间。
这就是扩展 AppCompat
主题时不需要 android:
前缀的原因,但如果您想要其他东西,假设 Theme.Holo
- 您有 2它们的不同样式 - 一种用于 Lollipop 之前的设备,一种用于 -21
,后者在每个样式属性前都有 android:
前缀。
这取决于您使用的主题及其上下文。这些属性由不同的来源定义。
如果属性名称以 android:
为前缀,则它是一个框架属性,只能用于定义了它的 Android 版本。
如果属性根本没有前缀,则属性由您自己的应用程序定义。这包括您使用库引入的所有属性定义。
在您的示例中,您为 AppCompat
定义了一个主题,它是支持库的一部分,因此也是您的应用程序的一部分。框架小部件不会直接识别这些颜色。