1

I am wanting to customise the rows of the overflow menu in the action bar. I found a great blog post explaining how to go about doing this, which seem simple enough. The link is below. http://scriptedpapers.com/2014/08/12/android-action-bar-overflow-menu-customization/

I am specifically wanting to change the background colour of the overflow menu rows so the theme that I am using looks like the following:

<resources>

<!--the theme applied to the application or activity -->
<style name="CustomActionBarTheme" parent="@android:style/Theme.Holo.Light.DarkActionBar">
    <item name="android:actionBarStyle">@style/CustomActionBar</item>
    <item name="android:homeAsUpIndicator">@drawable/upcaret</item>
    <item name="android:actionOverflowButtonStyle">@style/CustomOverflowButton</item>
    <item name="android:popupMenuStyle">@style/PopupMenu</item>
</style>

<!--ActionBar style -->
<style name="CustomActionBar" parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
    <item name="android:background">@color/customBlue</item>
</style>
<style name="CustomOverflowButton" parent="@android:style/Widget.Holo.Light.ActionButton.Overflow">
    <item name="android:src">@drawable/overflowbutton</item>
</style>
<style name="PopupMenu" parent="android:Widget.Holo.Light.ListPopupWindow">
    <item name="android:popupBackground">@color/customBlue</item>
</style>

Applying this theme to the application, the background colour of the overflow menu remains the same colour as the default for Holo.Light.DarkActionBar, despite setting a custom popupMenuStyle.

For my project, the minSdkVersion is 15 and targetSdkVersion is 19.

Does anyone have any ideas?

Thanks.

Jared Burrows
  • 54,294
  • 25
  • 151
  • 185
coldbuffet
  • 2,465
  • 5
  • 22
  • 24

1 Answers1

1

Try specifying a 9-patch drawable instead of a color.

Go here and choose the color that you want your rows to be by selecting a color from the "Popup color" drop-down.

The only file you need from the zip is menu_dropdown_panel.9.png.

Make sure to place this file in your various drawable-xxxx folders.

Then use it like this:

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

If it still doesn't work, add this to the above:

Add this line to your main theme (CustomActionBarTheme):

<item name="android:actionBarWidgetTheme">@style/PopupWrapper</item>

Then add this:

<style name="PopupWrapper" parent="@android:style/Theme.Holo">
    <item name="android:popupMenuStyle">@style/PopupMenu</item>
</style>
JDJ
  • 4,298
  • 3
  • 25
  • 44
  • Thanks for the suggestion. I tried it out, but it still doesn't seem to change the overflow menu row background. I'm completely stumped.. – coldbuffet Jan 05 '15 at 02:16
  • Yep, inside the tags I provide the attribute android:theme="@style/CustomActionBarTheme". Also, the other style customisations that I set seem to be working except for the overflow menu background. – coldbuffet Jan 05 '15 at 02:23
  • 1
    Temporarily change the parent theme to `android:Theme.Holo.Light` and see if that works – JDJ Jan 05 '15 at 02:26
  • Wow, that did the trick... thank you very much JDJ. I wonder why using Theme.Holo.Light.DarkActionBar prevents the background color to be changed? – coldbuffet Jan 05 '15 at 02:44
  • Glad it worked! I don't think it was working because Dark themes use an additional wrapper for popup menus. If you still want to use Theme.Holo.Light.DarkActionBar, you will probably have to use the method that I added to the end of the answer. – JDJ Jan 05 '15 at 02:56
  • Thanks for the updated answer. I can confirm that the popup wrapper code works beautifully. Thank you! – coldbuffet Jan 05 '15 at 03:28