Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 253
animaonline Avatar asked Nov 02 '14 12:11

animaonline


People also ask

How do I get a popup menu on Android?

Go to app > res > right-click > New > Android Resource Directory and give Directory name and Resource type as menu. Now, we will create a popup_menu file inside that menu resource directory. Go to app > res > menu > right-click > New > Menu Resource File and create a menu resource file and name it as popup_menu.

What is popup menu in Android user interface?

Android Popup Menu displays a list of items in a vertical list which presents the view that invoked the menu and is useful to provide an overflow of actions related to specific content.

What displays a pop up menu?

A PopupMenu displays a Menu in a modal popup window anchored to a View . The popup will appear below the anchor view if there is room, or above it if there is not. If the IME is visible the popup will not overlap it until it is touched. Touching outside of the popup will dismiss it.

How do I pass custom layout to PopupMenu?

You can use 9patch to get the shadow and rounded corners for the background. You can either add some styles to the popupMenu and achieve your UI or create popup Window. My conclusion is; if we define a style with parent="@android:style/Widget. PopupMenu" as parent, we override behaviour of our PopupMenu.


1 Answers

Not a full answer but what I found so far:

In past versions you needed to specify a drawable (Check https://github.com/StylingAndroid/StylingActionBar code and tutorials)

Apparently, now that is a color. To modify it you need to do specify the following theme:

<resources xmlns:android="http://schemas.android.com/apk/res/android">

    <style name="AppTheme" parent="android:Theme.Material.Light.DarkActionBar">
        <item name="android:actionBarPopupTheme">@style/popupNew</item>
    </style>

    <style name="popupNew" parent="android:ThemeOverlay.Material.Light">
        <item name="android:colorBackground">@color/red</item>
    </style>

</resources>

This works correctly if the theme applied to the app is just this. If I add android:actionBarPopupTheme to my existing theme, it doesn't work. I am trying to figure out why.

like image 179
Macarse Avatar answered Oct 12 '22 22:10

Macarse