android - ActionBarSherlock mirrod 属性——什么时候使用 "android:"前缀?

标签 android android-actionbar actionbarsherlock android-xml android-theme

在设计 ActionBarSherlock 样式时,我想知道什么时候必须使用前缀属性,什么时候使用非前缀属性,以及什么时候两者都使用。例如:

<item name="actionBarStyle">@style/Widget.Styled.ActionBar</item>
<item name="android:actionBarStyle">@style/Widget.Styled.ActionBar</item>

我在 ActionBarSherlock website 上找到了这个解释:

Mirrored Attributes

Due to limitations in Android's theming system any theme customizations must be declared in two attributes. The normal android-prefixed attributes apply the theme to the native action bar and the unprefixed attributes are for the custom implementation. Since both theming APIs are exactly the same you need only reference your customizations twice rather than having to implement them twice.

The easiest way to convey exactly what this entails is with an example. The following is the full theme from the “Styled” example mentioned above:

<style name="Theme.Styled" parent="Theme.Sherlock.Light.DarkActionBar">
    <item name="actionBarStyle">@style/Widget.Styled.ActionBar</item>
    <item name="android:actionBarStyle">@style/Widget.Styled.ActionBar</item>
</style>

<style name="Widget.Styled.ActionBar" parent="Widget.Sherlock.Light.ActionBar.Solid.Inverse">
    <item name="background">@drawable/bg_striped</item>
    <item name="android:background">@drawable/bg_striped</item>

    <item name="backgroundSplit">@drawable/bg_striped_split</item>
    <item name="android:backgroundSplit">@drawable/bg_striped_split</item>
</style>

我认为,非前缀属性只需要用于 API 级别 11 之前不存在的属性。但是为什么会有 android:background 以及 background 示例中的属性? android:background 自 API 级别 1 以来就存在。有人可以提供有关这些镜像属性的更多详细信息吗?

最佳答案

根据我对您引用的 ActionBarSherlock 文档的理解,当 ActionBarSherlock 使用 native 版本的 ActionBar (也就是说,在运行 Android 3+ 的设备上,如果它可用),并且当 ActionBarSherlock 实际上必须使用它自己的 ActionBar 组件实现时,在旧版本上使用无前缀版本。

简而言之,Android 原生功能使用 android 前缀的属性,自定义组件使用非前缀版本。

无论如何,在为 ActionBarSherlock 对象设置主题时,您似乎总是必须同时设置前缀和非前缀属性。

关于android - ActionBarSherlock mirrod 属性——什么时候使用 "android:"前缀?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14154392/

相关文章:

android - 任何用于 SQL 的 kotlin ORM?

Android禁用菜单点击声音

android - 当主题为 style.xml 中的 NoActionBar 时如何添加菜单选项

引用 ABS 时 Android SlidingMenu 错误

android - 我的 Android XML 文件找不到 ActionBarSherlock 主题

Android - onOptionsItemSelected UI 卡住直到完成

android - 在我的项目中导入 android-crop 库

Android.mk 在路径中通配额外的 'jni'?

android - 让 Google Play Services 4.0.30 与 Android Studio 0.4.2 和 Gradle 0.7 配合使用

android - LeftNavBar 在 Activity 顶部创建黑条