Material Card View Change Ripple Color

1.3k Views Asked by At

I am having a Material Card View in android studio and when i click on it its having the default gray black ripple can i change the ripple color to something else for example colorPrimary.

Below is my Material Card View

<com.google.android.material.card.MaterialCardView
            android:id="@+id/mcv_advert_preview"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:clickable="true"
            android:focusable="true"
            android:theme="@style/MaterialTheme"
            app:cardCornerRadius="5dp"
            app:cardElevation="1dp"
            app:cardUseCompatPadding="true"
            app:contentPadding="10dp"
            app:strokeWidth="1dp">

 </com.google.android.material.card.MaterialCardView>

1

There are 1 best solutions below

0
che10 On

Just use the following property to do so

app:rippleColor=""

You can use it as follows

<com.google.android.material.card.MaterialCardView
        android:id="@+id/mcv_advert_preview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:clickable="true"
        android:focusable="true"
        android:theme="@style/MaterialTheme"
        app:cardCornerRadius="5dp"
        app:cardElevation="1dp"
        app:rippleColor="?colorPrimary"
        app:cardUseCompatPadding="true"
        app:contentPadding="10dp"
        app:strokeWidth="1dp">

    </com.google.android.material.card.MaterialCardView>