I'm using the v7 support library in order to have an ActionBar on API Level 10+ (that's Android 2.3.3+). Now, I want to customize the look a bit, so I added an application theme. Excerpt of my values/styles.xml
:
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="actionBarStyle">@style/ActionBarStyle</item>
</style>
<style name="ActionBarStyle" parent="@style/Widget.AppCompat.ActionBar">
<item name="background">@drawable/bg_actionbar</item>
</style>
This works fine on Android 2.3.3, where the compat stuff is used. However, on Android 4.3 on an N4 (or an emulator), the styles are not applied. If I change the styles.xml
file to:
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="android:actionBarStyle">@style/ActionBarStyle</item>
</style>
<style name="ActionBarStyle" parent="@style/Widget.AppCompat.ActionBar">
<item name="android:background">@drawable/bg_actionbar</item>
</style>
(notice the added android:
prefix) it works on 4.3, but doesn't on 2.3 (styles not applied).
Is there any way I can get around this without specifying each <item>
twice, once with the prefix and once without?
There is a perfect example on the google docs site:
http://developer.android.com/guide/topics/ui/actionbar.html#StyleExample
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
parent="@style/Theme.AppCompat.Light">
<item name="android:actionBarStyle">@style/MyActionBar</item>
<item name="android:actionBarTabTextStyle">@style/TabTextStyle</item>
<item name="android:actionMenuTextColor">@color/actionbar_text</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">@style/MyActionBar</item>
<item name="actionBarTabTextStyle">@style/TabTextStyle</item>
<item name="actionMenuTextColor">@color/actionbar_text</item>
</style>
<!-- general styles for the action bar -->
<style name="MyActionBar"
parent="@style/Widget.AppCompat.ActionBar">
<item name="android:titleTextStyle">@style/TitleTextStyle</item>
<item name="android:background">@drawable/actionbar_background</item>
<item name="android:backgroundStacked">@drawable/actionbar_background</item>
<item name="android:backgroundSplit">@drawable/actionbar_background</item>
<!-- Support library compatibility -->
<item name="titleTextStyle">@style/TitleTextStyle</item>
<item name="background">@drawable/actionbar_background</item>
<item name="backgroundStacked">@drawable/actionbar_background</item>
<item name="backgroundSplit">@drawable/actionbar_background</item>
</style>
<!-- action bar title text -->
<style name="TitleTextStyle"
parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">@color/actionbar_text</item>
</style>
<!-- action bar tab text -->
<style name="TabTextStyle"
parent="@style/Widget.AppCompat.ActionBar.TabText">
<item name="android:textColor">@color/actionbar_text</item>
</style>
</resources>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With