Change the background color of CardView programmatically Change the background color of CardView programmatically android android

Change the background color of CardView programmatically


What you are looking for is:

CardView card = ...card.setCardBackgroundColor(color);

In XML

 card_view:cardBackgroundColor="@android:color/white"

Update: in XML

app:cardBackgroundColor="@android:color/white"


Use the property card_view:cardBackgroundColor:

<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"    android:id="@+id/card_view"    android:layout_width="fill_parent"    android:layout_height="150dp"    android:layout_gravity="center"    card_view:cardCornerRadius="4dp"    android:layout_margin="10dp"    card_view:cardBackgroundColor="#fff"    >


You can use this in XML

card_view:cardBackgroundColor="@android:color/white"

or this in Java

cardView.setCardBackgroundColor(Color.WHITE);