Object

CardDefaults

Contains the default values used by all card types.

RevenueCat

RevenueCat

Add subscriptions to your apps in minutes

Ad Get started for free
Android
object CardDefaults

Contains the default values used by all card types.

Properties

Android
const val SquareImageAspectRatio = 1f

Recommended aspect ratio Float to get square images, can be applied using the modifier androidx.compose.foundation.layout.aspectRatio.

Android
const val VerticalImageAspectRatio = 2f / 3

Recommended aspect ratio Float for vertical images, can be applied using the modifier androidx.compose.foundation.layout.aspectRatio.

Android
const val HorizontalImageAspectRatio = 16f / 9

Recommended aspect ratio Float for horizontal images, can be applied using the modifier androidx.compose.foundation.layout.aspectRatio.

Android
val ScrimBrush =
    Brush.verticalGradient(
        listOf(
            Color(red = 28, green = 27, blue = 31, alpha = 0),
            Color(red = 28, green = 27, blue = 31, alpha = 204),
        )
    )

Gradient used in cards to give more emphasis to the textual content that is generally displayed above an image.

Functions

shape

fun shape(
        shape: Shape = ContainerShape,
        focusedShape: Shape = shape,
        pressedShape: Shape = shape,
    ) = CardShape(shape = shape, focusedShape = focusedShape, pressedShape = pressedShape)

Creates a CardShape that represents the default container shapes used in a Card.

Parameters

shape the default shape used when the Card has no other Interactions.
focusedShape the shape used when the Card is focused.
pressedShape the shape used when the Card is pressed.

colors

@ReadOnlyComposable
    @Composable
    fun colors(
        containerColor: Color = MaterialTheme.colorScheme.surfaceVariant,
        contentColor: Color = contentColorFor(containerColor),
        focusedContainerColor: Color = containerColor,
        focusedContentColor: Color = contentColorFor(focusedContainerColor),
        pressedContainerColor: Color = focusedContainerColor,
        pressedContentColor: Color = contentColorFor(pressedContainerColor),
    ) =
        CardColors(
            containerColor = containerColor,
            contentColor = contentColor,
            focusedContainerColor = focusedContainerColor,
            focusedContentColor = focusedContentColor,
            pressedContainerColor = pressedContainerColor,
            pressedContentColor = pressedContentColor,
        )

Creates CardColors that represents the default container & content colors used in a Card.

Parameters

containerColor the default container color of this Card.
contentColor the default content color of this Card.
focusedContainerColor the container color of this Card when focused.
focusedContentColor the content color of this Card when focused.
pressedContainerColor the container color of this Card when pressed.
pressedContentColor the content color of this Card when pressed.

compactCardColors

@ReadOnlyComposable
    @Composable
    fun compactCardColors(
        containerColor: Color = MaterialTheme.colorScheme.surfaceVariant,
        contentColor: Color = Color.White,
        focusedContainerColor: Color = containerColor,
        focusedContentColor: Color = contentColor,
        pressedContainerColor: Color = focusedContainerColor,
        pressedContentColor: Color = focusedContentColor,
    ) =
        CardColors(
            containerColor = containerColor,
            contentColor = contentColor,
            focusedContainerColor = focusedContainerColor,
            focusedContentColor = focusedContentColor,
            pressedContainerColor = pressedContainerColor,
            pressedContentColor = pressedContentColor,
        )

Creates CardColors that represents the default colors used in a Compact Card.

Parameters

containerColor the default container color of this Card.
contentColor the default content color of this Card.
focusedContainerColor the container color of this Card when focused.
focusedContentColor the content color of this Card when focused.
pressedContainerColor the container color of this Card when pressed.
pressedContentColor the content color of this Card when pressed.

scale

fun scale(
        @FloatRange(from = 0.0) scale: Float = 1f,
        @FloatRange(from = 0.0) focusedScale: Float = 1.1f,
        @FloatRange(from = 0.0) pressedScale: Float = scale,
    ) = CardScale(scale = scale, focusedScale = focusedScale, pressedScale = pressedScale)

Creates a CardScale that represents the default scales used in a Card. Scales are used to modify the size of a composable in different Interaction states e.g. 1f (original) in default state, 1.1f (scaled up) in focused state, 0.8f (scaled down) in pressed state, etc.

Parameters

scale the default scale to be used for this Card.
focusedScale the scale to be used for this Card when focused.
pressedScale the scale to be used for this Card when pressed.

border

@ReadOnlyComposable
    @Composable
    fun border(
        border: Border = Border.None,
        focusedBorder: Border =
            Border(
                border = BorderStroke(width = 3.dp, color = MaterialTheme.colorScheme.border),
                shape = ContainerShape,
            ),
        pressedBorder: Border = focusedBorder,
    ) = CardBorder(border = border, focusedBorder = focusedBorder, pressedBorder = pressedBorder)

Creates a CardBorder that represents the border Borders applied on a Card in different Interaction states.

Parameters

border the default Border to be used for this Card.
focusedBorder the Border to be used for this Card when focused.
pressedBorder the Border to be used for this Card when pressed.

glow

fun glow(glow: Glow = Glow.None, focusedGlow: Glow = glow, pressedGlow: Glow = glow) =
        CardGlow(glow = glow, focusedGlow = focusedGlow, pressedGlow = pressedGlow)

Creates a CardGlow that represents the default Glows used in a card.

Parameters

glow the default Glow behind this Card.
focusedGlow the Glow behind this Card when focused.
pressedGlow the Glow behind this Card when pressed.