Changing actionBar dropdown background color

2019-06-26 00:48发布

enter image description here

How do i change the color of the background where it says "add contact" and "about". Now its kind of grayish, but i want it to be white! This is a actionBar with dropdown, not a spinner. And im not using that actionbarsherlock thing.

3条回答
\"骚年 ilove
2楼-- · 2019-06-26 01:36

For example, in you exisiting parent Style definition, add just 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 by defining your style:

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

The @drawable/menu_dropdown_panel_example is this:

enter image description here

You can either choose to use an image similar to the one above, or use an Color resource.

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

ActionBar styles can be easily created using this cool website: http://jgilfelt.github.com/android-actionbarstylegenerator/. I usually experiment a little here before deciding on the style. Plus, it lets you download the styles and all necessary resources. Just plug them in your app and you are good to go. :-)

UPDATED: I think I caused some confusion which has resulted in the loss of the shadow on your app's drop-down. You may have replaced all the <items> in your Style that I listed in the original suggestion. The edit should fix that.

UPDATE 2:

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

enter image description here enter image description here enter image description here

查看更多
我想做一个坏孩纸
3楼-- · 2019-06-26 01:44

You can simple override itemBackground item in your theme:

<style name="AppTheme" parent="Theme.AppCompat.Light">
    <item name="android:itemBackground">@color/skyBlue</item>
</style>
查看更多
叼着烟拽天下
4楼-- · 2019-06-26 01:48

Try to get styles from ActionBarStyleGenerator service. It has preview and makes all necessary drawable, xml and styles. There you can easily find and change required color and then find it in sources (in your case it is android:popupBackground).

查看更多
登录 后发表回答