Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

custom style action bar not working in android 4

For customizing my action bar I use code below in xml:

<style name="CustomActionbarTheme" parent="@style/Theme.AppCompat.Light">
    <item name="actionBarTabStyle">@style/customTab</item>
    <item name="actionBarStyle">@style/MyActionBar</item>
</style>

<style name="MyActionBar" parent="@style/Widget.AppCompat.ActionBar">
    <item name="background">@drawable/title_bar</item>
</style>

<style name="customTab" parent="@style/Widget.AppCompat.ActionBar.TabView">
    <item name="android:background">@drawable/tab_bg_selector</item>
</style>

I have no problem using api level 10 but when I run my code in higher api devices, action bars are in their default theme. I use support library v7 in my project.

like image 342
Mohamad Ghafourian Avatar asked Nov 30 '22 20:11

Mohamad Ghafourian


1 Answers

Update: as of AppCompat version 21, all API levels now use the non-prefixed style names so there is no longer a need to add the android: namespaced attributes.

Now obsolete: If you are using the support library v7 ActionBar, you need to declare your custom styles twice, once without the android: prefix (for <v11 support - this is what you have) and once with (for >=v11 support - you need to add this) as per the Styling the Action Bar guide.

like image 138
ianhanniballake Avatar answered Dec 10 '22 11:12

ianhanniballake