Customizing the CardView
suggest changeCardView provides a default elevation and corner radius so that cards have a consistent appearance across the platforms.
You can customize these default values using these attributes in the xml file:
card_view:cardElevation
attribute add elevation in CardView.card_view:cardBackgroundColor
attribute is used to customize background color of CardView’s background(you can give any color).card_view:cardCornerRadius
attribute is used to curve 4 edges of CardViewcard_view:contentPadding
attribute add padding between card and children of card
Note: card_view is a namespace defined in topmost parent layout view. xmlns:card_view=“http://schemas.android.com/apk/res-auto”
Here an example:
<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="wrap_content" card_view:cardElevation="4dp" card_view:cardBackgroundColor="@android:color/white" card_view:cardCornerRadius="8dp" card_view:contentPadding="16dp"> <!-- one child layout containing other layouts or views --> </android.support.v7.widget.CardView>
You can also do it programmatically using:
card.setCardBackgroundColor(....); card.setCardElevation(...); card.setRadius(....); card.setContentPadding();
Check the official javadoc for additional properties.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents