如何为抽屉菜单项创建带有圆角的波纹? [英] How to create a ripple with rounded corners for drawer menu items?
问题描述
我正在尝试为Drawer项目创建带有圆角的波纹.但是,我不知道如何实现这一目标.我试图创建一个自定义波纹并将其通过app:itemBackground
属性分配给NavigationView
,如下所示:
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.
您知道如何解决此问题吗?谢谢
Have you any idea how to solve this? Thanks
推荐答案
这就是我所做的.它为我消除了矩形波纹.试试看,让我知道是否有帮助.
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>
这篇关于如何为抽屉菜单项创建带有圆角的波纹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!