How to create a ripple with rounded corners for drawer menu items?
Asked Answered
P

1

3

I'm trying to create a ripple with rounded corners for the Drawer items. However, I can't figure out how to achieve that. I tried to create a custom ripple and assign it to the NavigationView through app:itemBackground property as follows:

<com.google.android.material.navigation.NavigationView
    android:id="@+id/navigation_view"
    style="@style/Widget.MaterialComponents.NavigationView"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    app:menu="@menu/menu_navigation"
    app:itemBackground="@drawable/custom_ripple"/>

custom_ripple

<ripple xmlns:android="http://schemas.android.com/apk/res/android"
    android:color="?android:attr/colorControlHighlight">
   <item android:id="@android:id/mask">
       <shape android:shape="rectangle">
          <solid android:color="#000000" />
          <corners android:radius="15dp" />
       </shape>
   </item>
   <item android:drawable="@drawable/rounded_corner" />
</ripple>

rounded_corner

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="@color/colorAccentTransparent" />
    <corners android:radius="6dp" />
</shape>

However, this doesn't work as expected. There seem to be two ripples: a rectangle and a ripple with rounded corners as you can see below.

Output

Have you any idea how to solve this? Thanks

Proconsul answered 17/4, 2019 at 23:7 Comment(0)
R
1

Here's what I have done. It removed the rectangular ripple for me. Give it a try and let me know if it's helpful.

<com.google.android.material.navigation.NavigationView
android:id="@+id/navigation_view"
android:theme="@style/NavigationItemNoRipple"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:menu="@menu/menu_navigation"
app:itemBackground="@drawable/custom_ripple"/>

styles.xml:

<style name="NavigationItemNoRipple">
    <item name="android:colorControlHighlight">@android:color/transparent</item>
</style>
Roy answered 30/4, 2019 at 16:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.