Search code examples
androidandroid-5.0-lollipopmaterial-designandroid-support-library

Styling the popup menu in Android 5.0


I'm making my app ready for Android 5.0, I'm using the latest compatibility library, here is what my style looks like.

<resources>
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="colorPrimary">@color/theme_accent</item>
        <item name="colorAccent">@color/theme_accent_secondary</item>
    </style>

    <style name="AppThemeDark" parent="Theme.AppCompat">
        <item name="colorPrimary">@color/theme_accent</item>
        <item name="colorAccent">@color/theme_accent_secondary</item>
    </style>
</resources>

(The ActionBar color is being set programmatically.)

Now, I want the overflow/popup menu to have the dark background like it had in the holo implementation, but I can't get it to work, here is what it looks like: enter image description here

I have tried setting the popupMenuStyle but it didn't work.

How can I make the popup menu darker?


Solution

  • Solved my problem by using this style:

    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="colorPrimary">@color/theme_accent</item>
        <item name="colorAccent">@color/theme_accent_secondary</item>
        <item name="actionBarStyle">@style/AbStyle</item>
        <item name="actionModeBackground">@color/actionmode_bg</item>
    </style>
    
    <style name="AbStyle" parent="Widget.AppCompat.Toolbar">
        <item name="elevation">2dp</item>
        <item name="displayOptions">homeAsUp|showTitle</item>
        <!--showHome-->
    </style>
    
    <style name="AppThemeDark" parent="Theme.AppCompat">
        <item name="colorAccent">@color/theme_accent_secondary</item>
        <item name="actionBarStyle">@style/AbStyle</item>
    </style>
    

    I had to use Widget.AppCompat.Toolbar as the parent actionBarStyle