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:cardElevationsets the elevation.card_view:cardBackgroundColorsets the background color.card_view:cardCornerRadiusrounds the four corners.card_view:contentPaddingadds padding between the card and its children.
card_view is a namespace on the card or a parent: xmlns:card_view="http://schemas.android.com/apk/res-auto".
Here is 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(Color.WHITE);
card.setCardElevation(4f);
card.setRadius(8f);
card.setContentPadding(16, 16, 16, 16);
Check the official javadoc for additional properties.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents