只需要在xml中给指定控件加上
android:foreground="?android:attr/selectableItemBackground"
即可。
如
<androidx.cardview.widget.CardView
android:id="@+id/card"
android:clickable="true"
android:longClickable="true"
android:foreground="?android:attr/selectableItemBackground"
>
</androidx.cardview.widget.CardView>