MaterialCardView

Provides a Material card.

This class supplies Material styles for the card in the constructor. The widget will display the correct default Material styles without the use of a style flag.

Stroke width can be set using the strokeWidth attribute. Set the stroke color using the strokeColor attribute. Without a strokeColor, the card will not render a stroked border, regardless of the strokeWidth value.

Cards implement Checkable, a default way to switch to android:checked_state is not provided. Clients have to call setChecked. This shows the app:checkedIcon and changes the overlay color.

Cards also have a custom state meant to be used when a card is draggable app:dragged_state. It's used by calling setDragged. This changes the overlay color and elevates the card to convey motion.

Note: The actual view hierarchy present under MaterialCardView is NOT guaranteed to match the view hierarchy as written in XML. As a result, calls to getParent() on children of the MaterialCardView, will not return the MaterialCardView itself, but rather an intermediate View. If you need to access a MaterialCardView directly, set an android:id and use findViewById.

For more information, see the component developer guidance and design guidelines.

Inheritors

Constructors

Link copied to clipboard
constructor(context: Context)
constructor(context: Context, attrs: AttributeSet)
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int)

Types

Link copied to clipboard
Positions the icon can be set to.
Link copied to clipboard
Interface definition for a callback to be invoked when the card checked state changes.

Properties

Link copied to clipboard
Gravity used to position the checked icon at the bottom|end of the Card.
Link copied to clipboard
Gravity used to position the checked icon at the bottom|start of the Card.
Link copied to clipboard
Gravity used to position the checked icon at the top|end of the Card.
Link copied to clipboard
Gravity used to position the checked icon at the top|start of the Card.

Functions

Link copied to clipboard
Sets the ripple color for this card.
Link copied to clipboard
Returns this cards's checked icon.
Link copied to clipboard
Gets the checked icon gravity for this card
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Returns the android.content.res.ColorStateList used to tint the checked icon.
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
@FloatRange(from = 0.0, to = 1.0)
open fun getProgress(): Float
Returns the interpolation on the Shape Path of the card.
Link copied to clipboard
open fun getRadius(): Float
Link copied to clipboard
Gets the ripple color for this card.
Link copied to clipboard
Due to limitations in the current implementation, if you modify the returned object call setShapeAppearanceModel again with the modified value to propagate the required changes.
Link copied to clipboard
Link copied to clipboard
Returns the stroke ColorStateList of this card view.
Link copied to clipboard
Returns the stroke width of this card view.
Link copied to clipboard
open fun isCheckable(): Boolean
Returns whether this Card is checkable.
Link copied to clipboard
open fun isChecked(): Boolean
Link copied to clipboard
open fun isDragged(): Boolean
Link copied to clipboard
Link copied to clipboard
open fun setBackground(drawable: Drawable)
Link copied to clipboard
open fun setBackgroundDrawable(drawable: Drawable)
Link copied to clipboard
Link copied to clipboard
open fun setCardElevation(elevation: Float)
Link copied to clipboard
open fun setCardForegroundColor(@Nullable foregroundColor: ColorStateList)
Sets the foreground color for this card.
Link copied to clipboard
open fun setCheckable(checkable: Boolean)
Sets whether this Card is checkable.
Link copied to clipboard
open fun setChecked(checked: Boolean)
Link copied to clipboard
open fun setCheckedIcon(@Nullable checkedIcon: Drawable)
Sets this card's checked icon.
Link copied to clipboard
open fun setCheckedIconGravity(checkedIconGravity: Int)
Sets the checked icon gravity for this card
Link copied to clipboard
open fun setCheckedIconMargin(@Dimension checkedIconMargin: Int)
Link copied to clipboard
open fun setCheckedIconMarginResource(@DimenRes checkedIconMarginResId: Int)
Sets the margin of the checked icon using a resource id.
Link copied to clipboard
Sets this card's checked icon using a resource id.
Link copied to clipboard
open fun setCheckedIconSize(@Dimension checkedIconSize: Int)
Sets the size of the checked icon
Link copied to clipboard
open fun setCheckedIconSizeResource(@DimenRes checkedIconSizeResId: Int)
Sets the size of the checked icon using a resource id.
Link copied to clipboard
open fun setCheckedIconTint(@Nullable checkedIconTint: ColorStateList)
Sets this checked icon color tint using the specified .
Link copied to clipboard
open fun setClickable(clickable: Boolean)
Link copied to clipboard
open fun setContentPadding(left: Int, top: Int, right: Int, bottom: Int)
Link copied to clipboard
open fun setDragged(dragged: Boolean)
Call this when the Card is being dragged to apply the right color and elevation changes.
Link copied to clipboard
open fun setMaxCardElevation(maxCardElevation: Float)
Link copied to clipboard
Register a callback to be invoked when the checked state of this Card changes.
Link copied to clipboard
open fun setPreventCornerOverlap(preventCornerOverlap: Boolean)
Link copied to clipboard
open fun setProgress(@FloatRange(from = 0.0, to = 1.0) progress: Float)
Sets the interpolation on the Shape Path of the card.
Link copied to clipboard
open fun setRadius(radius: Float)
Link copied to clipboard
open fun setRippleColor(@Nullable rippleColor: ColorStateList)
Sets the ripple color for this card.
Link copied to clipboard
open fun setRippleColorResource(@ColorRes rippleColorResourceId: Int)
Sets the ripple color resource for this card.
Link copied to clipboard
open fun setShapeAppearanceModel(@NonNull shapeAppearanceModel: ShapeAppearanceModel)
Sets the ShapeAppearanceModel that defines the shape.
Link copied to clipboard
open fun setStrokeColor(strokeColor: ColorStateList)
open fun setStrokeColor(@ColorInt strokeColor: Int)
Sets the stroke color of this card view.
Link copied to clipboard
open fun setStrokeWidth(@Dimension strokeWidth: Int)
Sets the stroke width of this card view.
Link copied to clipboard
open fun setUseCompatPadding(useCompatPadding: Boolean)
Link copied to clipboard
open fun toggle()