Change the color of the ActionBar popup menu

enter image description here

How to change the background color where it says “add contact” and “about”. Now its appearance is grayish, but I want it to be white! This is an actionBar with a dropdown, not a spinner. And I do not use this actionbarsherlock thing.

+4
source share
3 answers

For example, if you use the parent definition of Style , add only the android:popupMenuStyle attribute, as shown below:

 <style name="Theme.Example" parent="@android:style/Theme.Holo.Light"> <item name="android:popupMenuStyle">@style/PopupMenu.Example</item> ....... ....... </style> 

And override the android:popupMenuStyle attribute, specifying your style:

 <style name="PopupMenu.Example" parent="@android:style/Widget.Holo.Light.ListPopupWindow"> <item name="android:popupBackground">@drawable/menu_dropdown_panel_example</item> </style> 

@drawable/menu_dropdown_panel_example :

enter image description here

You can select an image similar to the above, or use the Color resource.

And this is for ActionBar by default. Not an ActionBarSherlock .; -)

ActionBar styles can be easily created using this cool website: http://jgilfelt.github.com/android-actionbarstylegenerator/ . I usually experiment a bit here before deciding on a style. In addition, it allows you to load styles and all the necessary resources. Just connect them to your application and you are good to go. :-)

UPDATED: I think I caused some confusion that led to the loss of shadow in your application. You may have replaced all <items> with the Style that I specified in the original sentence. Editing should fix this.

UPDATE 2:

Use these image resources instead of the @android:color/white value you are currently using. They are in XHDPI, HDPI, and MDPI order. Save them and use them in your style definition.

enter image description hereenter image description hereenter image description here

+7
source

Try to get styles from ActionBarStyleGenerator . It has a preview and does everything necessary for drawing, xml and styles. There you can easily find and change the desired color, and then find it in the sources (in your case, it is android: popupBackground).

0
source

You can simply override itemBackground in your theme:

 <style name="AppTheme" parent="Theme.AppCompat.Light"> <item name="android:itemBackground">@color/skyBlue</item> </style> 
0
source

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


All Articles