一般情况下,加入以下属性,即可达到点击波纹效果
<Button
android:foreground="?android:attr/selectableItemBackground"
/>
如果需要波纹效果限制在圆角范围内,可以这么定义 drawable, 然后引用之
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?attr/colorControlHighlight">
<item>
<shape
android:shape="rectangle">
<corners android:radius="90dp" />
<solid android:color="@color/global_color"/>
</shape>
</item>
</ripple>
在 CardView 中可以这么使用
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:cardBackgroundColor="@{bgColor}"
app:cardCornerRadius="10dp"
android:foreground="?android:attr/selectableItemBackgroundBorderless"
>