I am trying to change the color of an item when it pressed. I used the actionBarItemBackground
item in the action bar style, but nothing happens.. The color not changed...
Here my code:
<style name="ActionBarStyle" parent="@style/Widget.AppCompat.ActionBar.Solid">
<item name="android:background">@color/actionbar_background</item>
<item name="titleTextStyle">@style/ActionBarStyle.Title</item>
<item name="actionBarItemBackground">@drawable/action_bar_item_selector</item>
<item name="android:actionBarItemBackground" tools:ignore="NewApi">@drawable/action_bar_item_selector</item>
</style>
And the selector:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/pressed_item" android:state_focused="true"/>
<item android:drawable="@drawable/pressed_item" android:state_pressed="true"/>
<item android:drawable="@android:color/transparent"/>
</selector>
And the drawable:
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<solid android:color="#FF0000"/>
</shape>
What is worng? Someone?
actionBarItemBackground
isn't inherit of Widget.ActionBar
. You should be placing it in your root theme, wherever you apply your ActionBarStyle
, but not in your ActionBarStyle
. So, something like:
<style name="Your.Theme" parent="@style/Theme.AppCompat">
<item name="actionBarStyle">@style/ActionBarStyle</item>
<item name="android:actionBarStyle">@style/ActionBarStyle</item>
<item name="actionBarItemBackground">@drawable/action_bar_item_selector</item>
<item name="android:actionBarItemBackground" tools:ignore="NewApi">@drawable/action_bar_item_selector</item>
</style>
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