29

I would like custom background & text color for my overflow menu. It works fine with devices without hardware menu button, but I'm not able to style devices with hardware menu button. See the screenshots:

Screnshot from Galaxy Nexus Screenshot from Galaxy S3

I'm using these styles:

<style name="Theme.settleup" parent="@style/Theme.Sherlock.Light.DarkActionBar">
    <item name="android:popupMenuStyle">@style/settleup_PopupMenu</item> 
    <item name="android:actionMenuTextColor">@android:color/white</item>
</style>
<style name="settleup_PopupMenu" parent="@style/Widget.Sherlock.ListPopupWindow">
    <item name="android:popupBackground">@drawable/menu_dropdown_panel_settleup</item>
</style>

6 Answers 6

27
+50

I've looked into the problem. And there seems to be no way in changing textColor for the options menu for Android >= 4.0 devices with HW menu key. Not even changing primary, secondary or tertiary colors affected the text color.
The only "solution" that comes to my mind now is some pretty nasty use of java reflection API.

However, you can set the background of the bottom options menu of Android >= 4.0 HW key devices separately from the background of the non-HW key dropdown menu.

You already has the styling for non-HW key dropdown menu. The non-HW key dropdown menu is defined by android:popupMenuStyle (and popupMenuStyle):

<style name="Theme.settleup" parent="@style/Theme.Sherlock.Light.DarkActionBar">
    <item name="android:popupMenuStyle">@style/settleup_PopupMenu</item> 
</style>

But the background of the Android >= 4.0 HW key bottom options menu is defined with android:panelBackground item in the theme:

<style name="Theme.settleup" parent="@style/Theme.Sherlock.Light.DarkActionBar">
    <item name="android:panelBackground">@drawable/mybackground</item>
</style>

Since it seems to be a problem to change the text color for bottom options menu on Android >= 4.0 HW key devices, I would suggest to leave this part to its default styling.

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks, this actually does solve my problem. Bottom menu doesn't need to be styled since it's not visually connected to the ActionBar.
I managed to change to color using the android:textAppearanceLargePopupMenu attribute. Set it in the application/activity theme and then set the textColor attribute in that style.
@YoelGluschnaider what parent style did you have for your android:textAppearanceLargePopupMenu item?
+1 for android:panelBackground. I've been looking at styling this menu for the past two days and this is the first time I've seen it mentioned.
I don't know what to put in @style/settleup_PopupMenu
6

Been digging in the AppCompat theming but whatever I tried the textColor remains white. What I do now is just popup the Toolbar menu manually like this:

@Override
public boolean onKeyUp(int keycode, KeyEvent e) {
   switch (keycode) {
       case KeyEvent.KEYCODE_MENU:
           if ( getSupportActionBar() != null ) {
               getSupportActionBar().openOptionsMenu();

               return true;
           }
   }

   return super.onKeyUp(keycode, e);
}

Pressing the menu button while the menu is open magically closes it.

Who needs the ugly black bottom aligned menu anyway?

Comments

5

You can apply styles and Themes in Overflow MenuItem as per below. OverFlow Menu is ListView so, we can apply theme as per listview.

Apply below code in styles.xml

<style name="AppTheme" parent="@android:style/Theme.Holo.Light">
    <item name="android:dropDownListViewStyle">@style/PopupMenuListView</item>
            <item name="android:actionBarWidgetTheme">@style/PopupMenuTextView</item>
            <item name="android:popupMenuStyle">@style/PopupMenu</item>
            <item name="android:listPreferredItemHeightSmall">40dp</item>
    </style>

    <!-- Change Overflow Menu ListView Divider Property -->
        <style name="PopupMenuListView" parent="@android:style/Widget.Holo.ListView.DropDown">
            <item name="android:divider">@color/app_navigation_divider</item>
            <item name="android:dividerHeight">1sp</item>
            <item name="android:listSelector">@drawable/list_selector</item>
        </style>

        <!-- Change Overflow Menu ListView Text Size and Text Size -->
        <style name="PopupMenuTextView" parent="@android:style/Widget.Holo.Light.TextView">
            <item name="android:textColor">@color/app_white</item>
            <item name="android:textStyle">normal</item>
            <item name="android:textSize">18sp</item>
            <item name="android:drawablePadding">25dp</item>
            <item name="android:drawableRight">@drawable/navigation_arrow_selector</item>
        </style>

        <!-- Change Overflow Menu Background -->
        <style name="PopupMenu" parent="android:Widget.Holo.Light.ListPopupWindow">
            <item name="android:popupBackground">@drawable/menu_overflow_bg</item>
        </style>

1 Comment

how to set height to the list? layout_height, height, maxHeight are not working
3

For AppCompat theme:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="actionBarPopupTheme">@style/HardwareOptionMenu</item>
</style>

<style name="HardwareOptionMenu" parent="ThemeOverlay.AppCompat.Dark">
    <item name="android:textColorSecondary">@color/white</item>
    <item name="android:colorBackground">@color/black</item>
</style>

Comments

1

try also adding the items without android prefix

<style name="Theme.settleup" parent="@style/Theme.Sherlock.Light.DarkActionBar">
    <item name="android:popupMenuStyle">@style/settleup_PopupMenu</item>
    <item name="popupMenuStyle">@style/settleup_PopupMenu</item> 
    <item name="android:actionMenuTextColor">@android:color/white</item>
    <item name="actionMenuTextColor">@android:color/white</item>
</style>
<style name="settleup_PopupMenu" parent="@style/Widget.Sherlock.ListPopupWindow">
    <item name="android:popupBackground">@drawable/menu_dropdown_panel_settleup</item>
    <item name="popupBackground">@drawable/menu_dropdown_panel_settleup</item>
</style>

1 Comment

I have it there like this, I removed it in my question for clarity. AFAIK attributes without android prefix are only for emulated ActionBar <4.0. But I have problem with native actionbar on devices with Android>=4.0 (with hardware menu button)
1

what you can do if you really have to change the text color of the menu from the right picture could be the following "hack":

SpannableStringBuilder text = new SpannableStringBuilder();
        text.append("MenuItem1");
        text.setSpan(new ForegroundColorSpan(Color.WHITE), 0, text.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

        menu.add(Menu.NONE, MENU_ITEM_1, Menu.NONE, null).setTitle(text);

I agree it's not the cleanest way (I would say it's quite ugly because you have to pay attention in each activity where you have such a menu and the title of each menu item needs to be changed using this logic) but it's something that displays the expected result. Let me know if it helped you.

Cheers!

Comments

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.