Both Approach should work the same way.
1) If you want cardview to respond to touch feedback then use this one in cardview.
android:foreground="?android:attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
but if above approach is not working then you can set this property on child view group (Linear/Relative etc) of cardview.
android:background="?android:attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
But then itemView
of ViewHolder will not respond to the touch event. since its been consumed by child view so you have to set clicklistener on childview to work on further with listener in recyclerview adapter, this way we can enable touch as well as click events on row items of recyclerview in our adapter.
if you have hard time following the touch and click on views in cardview with ripple then this might be helpful. Touch Feedback Problem
2.) The second approach is to use the traditional way of using custom touch selector drawable and set as background.
<?xml version="1.0" encoding="utf-8"?>
<ripple
xmlns:android="http://schemas.android.com/apk/res/android"
android:color="your ripple color">
<item>
<selector>
<item android:state_selected="true">
<color android:color="your selected color" />
</item>
<item android:state_activated="true">
<color android:color="your selected color" />
</item>
<item>
<color android:color="your normal color" />
</item>
</selector>
</item>
</ripple>
Docs Ripple Drawable