zawadz88/MaterialPopupMenu

How can I add rounded corners to Popup menu?

Closed this issue · 3 comments

How can I add rounded corners to Popup menu?

Hi,
I hope this will be possible once AndroidX migration happens: #31
I haven't checked this though... I'll try to put a sample in of how to do this

Thank you @zawadz88

@TikTak123 So this should be possible even in the current version.
You need to create a drawable with rounded corners e.g.

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="@color/mpm_material_grey_50"/>

    <corners
        android:radius="8dp"/>

    <padding
        android:bottom="8dp"
        android:top="8dp"/>

</shape>

and then reference that drawable in a custom style declared in your styles.xml e.g.

    <style name="Widget.MPM.Menu.Dark.CustomBackground">
        <item name="android:popupBackground">@drawable/mtrl_popupmenu_background</item>
    </style>

The last piece of the puzzle is to use that style when building the popup menu:

val popupMenu = popupMenu {
    style = R.style.Widget_MPM_Menu_Dark_CustomBackground
    // ... place your items here
}

This is how this might look like:
screenshot_1541005735