1

Im using the appcompat library to implement an action bar. While using a custom style it gives an error android:actionBarStyle requires API level 11 (current min is 10). I want the app to be compatible with android 2.3. Im using the google sample code.

themes.xml
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
       parent="@style/Theme.AppCompat.Light.DarkActionBar">
    <item name="android:actionBarStyle">@style/MyActionBar</item>

    <!-- Support library compatibility -->
    <item name="actionBarStyle">@style/MyActionBar</item>
</style>

<!-- ActionBar styles -->
<style name="MyActionBar"
       parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
    <item name="android:background">@drawable/actionbar_background</item>

    <!-- Support library compatibility -->
    <item name="background">@drawable/actionbar_background</item>
</style>

Sahil Lombar
  • 145
  • 1
  • 11
  • Possible duplicate of [android:actionBarStyle requires API level 11](http://stackoverflow.com/questions/15339150/androidactionbarstyle-requires-api-level-11) – blahdiblah Nov 04 '13 at 18:45

1 Answers1

2

AppCompat is compatible with 2.3, but you need to define 2 styles (as you have above): 1 for the native actionbar implementation (android:actionBarStyle) and one for the compatibility implementation (actionBarStyle).

If you define both those styles in your values/styles.xml, you will get compile errors - because values/styles.xml is compiled for all api versions, and 2.3 doesn't know about android:actionBarStyle.

So you can duplicate your styles. Have a values/styles.xml and a values-v14/styles.xml

The styles in values-v14/styles.xml will override any styles in values/styles.xml when run on a api 14 and above device.

Or you can keep all your styles in the one values/styles.xml, but on the attributes you are getting the error on, add a tools:targetApi="14" to the tag, which tells the compiler to ignore this on non api 14 devices.

e.g.

<item name="android:actionBarStyle" tools:targetApi="14">@style/MyActionBar</item>
athor
  • 6,848
  • 2
  • 34
  • 37