1

I am able to style overflow menu which pops up from action bar but I am not able to style overflow menu which pops up from hardware menu button.

I am interested in styling states of selector for the item in menu.

any ideas are welcome?

1
  • are you using a custom layout (XML) for styling the overflow menu? Commented Jan 27, 2015 at 12:49

1 Answer 1

2

For customize the popup menu which is displayed with the hardware menu button, you need to have this item in your app theme:

<style name="CustomTheme" parent="@style/Theme.AppCompat.Light">
    <item name="android:itemBackground">@drawable/ab_item_selector</item>  
</style> 

You can change @style/Theme.AppCompat.Light according to your needs (as Holo or something else). Then, the drawable named ab_item_selector might be this:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- selected state -->
    <item 
        android:drawable="@drawable/item_selected" 
        android:state_selected="true"></item>
    <!-- pressed state -->
    <item 
        android:drawable="@drawable/item_pressed" 
        android:state_pressed="true"></item>
    <!-- normal state -->
    <item 
        android:drawable="@drawable/item_disabled"></item>
</selector> 

Hope this helps.


UPDATE

For dividers, I'm not sure but it might be:

<style name="CustomTheme" parent="@style/Theme.AppCompat.Light">
    <item name="android:dropDownListViewStyle">@style/CustomDropDown</item>
    <item name="dropDownListViewStyle">@style/CustomDropDown</item>
</style>

<style name="CustomDropDown" parent="@style/Widget.AppCompat.Light.ListView.DropDown">
    <item name="android:dividerHeight">1dip</item>
    <item name="android:divider">@drawable/dropdown_divider</item>
</style>  
Sign up to request clarification or add additional context in comments.

8 Comments

With this I can see the background color changing but I do not see the pressed state reflected properly. But I think we are getting near, may be need fix selector now.
Yes, I saw that you already updated answer with selected. I should have refreshed but this fixes my problem. Thanks.
Indeed, you have to play with the selector states as focused, pressed/focused, pressed/selected, etc. Personally, I used focused/enabled, focused/pressed and pressed.
Any Idea how to customize those dividers in menu item.
I updated my answer, @VendettaDroid. However, be careful with this item, it customizes all the listview in your app. Not sure but it might be this attribute to stylize your menu. HTH
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.