1

When styling ActionBarSherlock I was wondering when I have to use the prefixed attribute, when the non-prefixed attribute, and when both. For example:

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

I found this explanation on the 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>

I thought, non-prefixed attributes only have to be used for attributes, that did not exist before API level 11. But why is there an android:background as well as a background attribute in the example? android:background exists since API level 1. Can someone please give some more details about these mirrored attributes?

Cesar V.
  • 36
  • 4

2 Answers2

1

From what I understand of the ActionBarSherlock documentation you quote, the android-prefixed attribute (which you would have been the only one to set if you used the "normal" ActionBar) is used when ActionBarSherlock uses the native version of ActionBar (that is, on devices running Android 3+, where it's available), and the non-prefixed version is used on older versions, when ActionBarSherlock actually has to use its own implementation of the ActionBar component.

In short, android-prefixed attributes are used by Android native features, and non-prefixed versions are used by custom components.

Anyway, it looks like you always have to set both prefixed and non-prefixed attribute when theming an ActionBarSherlock object.

mbrenon
  • 4,851
  • 23
  • 25
0

Simple rule is anywhere you are inheriting from parent="Widget.Sherlock.etc" then you should have dual attributes.

The exception being direct styles like Text and Button don't as you are only passing your style to that TextView/Button directly, I would however always inherit from the parent/current style defined in the abs__styles.xml, that way you will always get the correct spacing etc..

Chris.Jenkins
  • 13,051
  • 4
  • 60
  • 61