10

I have an app that uses the AppCompat support libary for ActionBars. Now I tried to create a new themes.xml file with some style for that purpose.

<!-- Application theme. -->
<style name="AppTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
    <item name="android:actionBarStyle">@style/MyActionBar</item>
    <item name="actionBarStyle">@style/MyActionBar</item>
</style>

So just the same way it is done here: http://developer.android.com/guide/topics/ui/actionbar.html#StyleExample However, Eclipse throws an error here and says:

android:actionBarStyle requires API level 11 (current min is 8) themes.xml

How can this be as I am using the support libary?

George Kagan
  • 5,913
  • 8
  • 46
  • 50
benestar
  • 552
  • 4
  • 12

1 Answers1

13

Add the below in styles.xml under res/values-14

<style name="Theme.Styled" parent="@style/Theme.AppCompat.Light">
    <!-- Setting values in the android namespace affects API levels 14+ -->
    <item name="android:actionBarStyle">@style/Widget.Styled.ActionBar</item>

</style>

<style name="Widget.Styled.ActionBar" parent="@style/Widget.AppCompat.Light.ActionBar">
    <!-- Setting values in the android namespace affects API levels 14+ -->
    <item name="android:background">#FFFFFF</item>

</style>

You would then need add the following into the values folder: res/values/styles.xml

<style name="Theme.Styled" parent="@style/Theme.AppCompat.Light">
    <!-- Setting values in the default namespace affects API levels 7-13 -->
    <item name="actionBarStyle">@style/Widget.Styled.ActionBar</item>
</style>

<style name="Widget.Styled.ActionBar" parent="@style/Widget.AppCompat.Light.ActionBar">
    <!-- Setting values in the default namespace affects API levels 7-13 -->
    <item name="background">#FFFFFF</item>
</style>

For more details

http://android-developers.blogspot.in/2013/08/actionbarcompat-and-io-2013-app-source.html

Notice the change for API level 14+

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

To API level 7-13

 <item name="actionBarStyle">@style/Widget.Styled.ActionBar</item>
Sankar V
  • 4,794
  • 3
  • 38
  • 56
Raghunandan
  • 132,755
  • 26
  • 225
  • 256
  • Though I guess you mean `values-v14` as written in the link. – benestar Nov 17 '13 at 16:16
  • @user2433059 styles in res/values/styles.xml and res/values-14/styles.xml is what i meant – Raghunandan Nov 17 '13 at 17:15
  • @user2433059 see the second part of the answer also. that is for api 7-13. Action Bar is available is 11 and so you use app compact support library below api level 11 – Raghunandan Nov 17 '13 at 17:44
  • for `red/values-v14` would you keep `AppCompat` or should you really swap it to `Holo`? – xLite Dec 03 '13 at 20:27
  • @xLite r u using actionbar below api 11 then follow the link in my post. that is all you need to do – Raghunandan Dec 03 '13 at 20:29
  • @Raghunandan I know, Below 11 I use `AppCompat` but if it's 11+ is it good practice to change it to `Holo`, so it's `Theme.Holo.Light` for 11+ in `res/values-v11/styles.xml`?? – xLite Dec 03 '13 at 20:34
  • @xLite if its 11+ no need to use appcompact at all – Raghunandan Dec 03 '13 at 20:37
  • just tried it, turns out you *have* to use `AppCompat` as long as your `Activity` is extending `ActionBarActivity`.. damn – xLite Dec 03 '13 at 20:46