I am using a RecyclerView
with its item as a CardView
. I have the card view's background as android:background="?android:attr/selectableItemBackground"
.
I tried setting the foreground
, tried giving a LinearLayout
as a parent and set its background etc, but nothing works.
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="?android:attr/selectableItemBackground"
card_view:cardCornerRadius="2dp"
card_view:cardElevation="2dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp">
<!--TextView-->
<!--Imageview-->
<!--Textview-->
</RelativeLayout>
</android.support.v7.widget.CardView>
Why is this behavior?
Edit: The CardView
has an onClickListener
which works.
Edit 2: I added a RelativeLayout
as a parent to the CardView
. And made that clickable and gave it a selectable item background. Still no ripples.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?android:attr/selectableItemBackground"
android:clickable="true"
android:focusable="true">
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
card_view:cardCornerRadius="2dp"
card_view:cardElevation="2dp">
<!-- ... -->
</android.support.v7.widget.CardView>
</RelativeLayout>
Edit 3: I posting my exact layout code structure. I had failed to mention the data binding part. But I hope that is not blocking the ripples.
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<import type="android.view.View"/>
<variable
name="viewModel"
type="com.xxx.xxx.viewmodel.genericviewmodel" />
</data>
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:focusable="true"
android:orientation="vertical"
android:foreground="?android:attr/selectableItemBackground"
card_view:cardCornerRadius="2dp"
card_view:cardElevation="2dp">
<RelativeLayout
android:id="@+id/c_open_case_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp">
<!--TextView-->
<!--Imageview-->
<!--Textview-->
<!--TextView-->
<!--Imageview-->
<!--Textview-->
</RelativeLayout>
</android.support.v7.widget.CardView>
</layout>