rafanasil rafanasil - 9 days ago 5
Android Question

RecyclerView + CardView + Touch feedback

Has anybody solved the mystery of the CardView without touch feedback when it's inside a RecyclerView?

I have a RecyclerView with a bunch of CardViews (a CardList). When I click on any CardView, I start another Activity. That's working pretty fine, but I can't see any touch feedback when I click on the CardView.

Just in time, I've already configured my CardView (XML) with these:

android:clickable="true"
android:background="?android:selectableItemBackground"


Thanks!

Answer

Background:

The CardView ignores android:background in favor of app:cardBackground which can only be color. The border and shadow are in fact part of the background so you cannot set your own.

Solution:

Make the layout inside the CardView clickable instead of the card itself. You already wrote both attributes needed for this layout:

android:clickable="true"
android:background="?android:selectableItemBackground"
Comments