Android data binding Recycleview set cardview color with colorStateList

I am trying to set the background color of a cardview inside a recycleview through the data binding.

I have this on cardview xml layout:
app:cardBackgroundColor="@{user.gender.equals(`M`) ? @color/card_male_color : @color/card_female_color }"

card_male_color.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
   <item android:color="@color/selectedColor" android:state_selected="true"/>
   <item android:color="@color/selectedColor" android:state_pressed="true"/>
   <item android:color="@color/card_color_male"/>
</selector> 

But when the card is selected the background does not change color.

Source: Android Questions

LEAVE A COMMENT