Actionbar menuitem pressed background color

I created an action bar with ActionBarSherlock. I want to stylize the action bar, so when I click on the menuitem element (the drop-down element that appears from the overflow), the background of the menuitem should change color. (Now it changes to blue by default, I want it to be a different color).

After a lot of googleing and testing, I came up with the following:

themes.xml :

 <style name="AppTheme" parent="Holo.Theme"> <item name="android:popupMenuStyle">@style/PopupMenuStyle</item> <item name="popupMenuStyle">@style/PopupMenuStyle</item> </style> <style name="PopupMenuStyle" parent="@style/Widget.Sherlock.PopupMenu"> <item name="android:dropDownSelector">@drawable/menu_selector</item> </style> 

menu_selector.xml : (e.g. abs__list_selector_holo_dark.xml )

 <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_window_focused="false" android:drawable="@android:color/transparent" /> <item android:state_focused="true" android:state_enabled="false" android:state_pressed="true" android:drawable="@drawable/abs__list_selector_disabled_holo_dark" /> <item android:state_focused="true" android:state_enabled="false" android:drawable="@drawable/abs__list_selector_disabled_holo_dark" /> <item android:state_focused="true" android:state_pressed="true" android:drawable="@color/AppRed" /> <item android:state_focused="false" android:state_pressed="true" android:drawable="@color/AppRed" /> <item android:state_focused="true" android:drawable="@drawable/abs__list_focused_holo" /> <item android:drawable="@color/AppRed" /> </selector> 

Unfortunately, the background is still changing to blue, not red. What am I missing here?

+4
source share
1 answer

This will lead to the creation of ActionBar styles for you, you can only change the accent color, which will change the selector of the action bar elements (you still have to copy all the files that it generates into your project):

http://jgilfelt.imtqy.com/android-actionbarstylegenerator/

+5
source

Source: https://habr.com/ru/post/1492809/


All Articles