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.

0

1 Answer 1

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>
Sign up to request clarification or add additional context in comments.

6 Comments

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..
Yep, inside the <application> 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.
Temporarily change the parent theme to android:Theme.Holo.Light and see if that works
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?
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.
|

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.