zawadz88 / MaterialPopupMenu

Shows Material popup menus grouped in sections & more
Apache License 2.0
646 stars 57 forks source link

How can I add rounded corners to Popup menu? #32

Closed TikTak123 closed 5 years ago

zawadz88 commented 5 years ago

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

TikTak123 commented 5 years ago

Thank you @zawadz88

zawadz88 commented 5 years ago

@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