Card
Functions summary
Unit |
@ComposableCard is a component used to group related information into a single digestible unit. |
Unit |
@ComposableCard is a component used to group related information into a single digestible unit. |
Functions
Card
@Composable
fun Card(
modifier: Modifier = Modifier,
title: (@Composable () -> Unit)? = null,
subtitle: (@Composable () -> Unit)? = null,
header: (@Composable () -> Unit)? = null,
leadingIcon: (@Composable () -> Unit)? = null,
trailingIcon: (@Composable () -> Unit)? = null,
shape: Shape = CardDefaults.shape,
color: Color = GlimmerTheme.colors.surface,
contentColor: Color = calculateContentColor(color),
contentPadding: PaddingValues = CardDefaults.contentPadding,
interactionSource: MutableInteractionSource? = null,
content: @Composable () -> Unit
): Unit
Card is a component used to group related information into a single digestible unit. A card can adapt to display a wide range of content, from simple text blurbs to more complex summaries with multiple elements. A card contains text content, and may also have any combination of title, subtitle, leadingIcon, and trailingIcon. If specified, title is placed on top of the subtitle, which is placed on top of the content. A card fills the maximum width available by default.
This Card is focusable - see the other Card overload for a clickable Card.
Cards can also be combined with a TitleChip. See the documentation for TitleChip for more information / sample code.
A simple Card with just text:
import androidx.xr.glimmer.Card import androidx.xr.glimmer.Text Card { Text("This is a card") }
A Card with a trailing icon:
import androidx.xr.glimmer.Card import androidx.xr.glimmer.Icon import androidx.xr.glimmer.Text Card(trailingIcon = { Icon(FavoriteIcon, "Localized description") }) { Text("This is a card with a trailing icon") }
A Card with a title, subtitle, and a leading icon:
import androidx.xr.glimmer.Card import androidx.xr.glimmer.Icon import androidx.xr.glimmer.Text Card( title = { Text("Title") }, subtitle = { Text("Subtitle") }, leadingIcon = { Icon(FavoriteIcon, "Localized description") }, ) { Text("This is a card with a title, subtitle, and leading icon") }
A card with a title and a header image:
import androidx.compose.foundation.Image import androidx.compose.ui.layout.ContentScale import androidx.xr.glimmer.Card import androidx.xr.glimmer.Text Card( title = { Text("Title") }, header = { Image(MyHeaderImage, "Localized description", contentScale = ContentScale.FillWidth) }, ) { Text("This is a card with a title and header image") }
| Parameters | |
|---|---|
modifier: Modifier = Modifier |
the |
title: (@Composable () -> Unit)? = null |
optional title to be placed above |
subtitle: (@Composable () -> Unit)? = null |
|
header: (@Composable () -> Unit)? = null |
optional header image to be placed at the top of the card. This image should typically fill the max width available, for example using |
leadingIcon: (@Composable () -> Unit)? = null |
optional leading icon to be placed before |
trailingIcon: (@Composable () -> Unit)? = null |
optional trailing icon to be placed after |
shape: Shape = CardDefaults.shape |
the |
color: Color = GlimmerTheme.colors.surface |
background color of this card |
contentColor: Color = calculateContentColor(color) |
content color used by components inside |
contentPadding: PaddingValues = CardDefaults.contentPadding |
the spacing values to apply internally between the container and the content. Note that there is additional padding applied around the content / text / icons inside a card, this only affects the outermost content padding. |
interactionSource: MutableInteractionSource? = null |
an optional hoisted |
content: @Composable () -> Unit |
the main content / body text to display inside this card. This is recommended to be limited to 10 lines of text. |
Card
@Composable
fun Card(
onClick: () -> Unit,
modifier: Modifier = Modifier,
title: (@Composable () -> Unit)? = null,
subtitle: (@Composable () -> Unit)? = null,
header: (@Composable () -> Unit)? = null,
leadingIcon: (@Composable () -> Unit)? = null,
trailingIcon: (@Composable () -> Unit)? = null,
shape: Shape = CardDefaults.shape,
color: Color = GlimmerTheme.colors.surface,
contentColor: Color = calculateContentColor(color),
contentPadding: PaddingValues = CardDefaults.contentPadding,
interactionSource: MutableInteractionSource? = null,
content: @Composable () -> Unit
): Unit
Card is a component used to group related information into a single digestible unit. A card can adapt to display a wide range of content, from simple text blurbs to more complex summaries with multiple elements. A card contains text content, and may also have any combination of title, subtitle, leadingIcon, and trailingIcon. If specified, title is placed on top of the subtitle, which is placed on top of the content. A card fills the maximum width available by default.
This Card is focusable and clickable - see the other Card overload for a Card that is only focusable.
Cards can also be combined with a TitleChip. See the documentation for TitleChip for more information / sample code.
A simple clickable Card with just text:
import androidx.xr.glimmer.Card import androidx.xr.glimmer.Text Card(onClick = {}) { Text("This is a card") }
A clickable Card with a trailing icon:
import androidx.xr.glimmer.Card import androidx.xr.glimmer.Icon import androidx.xr.glimmer.Text Card(onClick = {}, trailingIcon = { Icon(FavoriteIcon, "Localized description") }) { Text("This is a card with a trailing icon") }
A clickable Card with a title, subtitle, and a leading icon:
import androidx.xr.glimmer.Card import androidx.xr.glimmer.Icon import androidx.xr.glimmer.Text Card( onClick = {}, title = { Text("Title") }, subtitle = { Text("Subtitle") }, leadingIcon = { Icon(FavoriteIcon, "Localized description") }, ) { Text("This is a card with a title, subtitle, and leading icon") }
A clickable Card with a title and a header image:
import androidx.compose.foundation.Image import androidx.compose.ui.layout.ContentScale import androidx.xr.glimmer.Card import androidx.xr.glimmer.Text Card( onClick = {}, title = { Text("Title") }, header = { Image(MyHeaderImage, "Localized description", contentScale = ContentScale.FillWidth) }, ) { Text("This is a card with a title and header image") }
| Parameters | |
|---|---|
onClick: () -> Unit |
called when this card item is clicked |
modifier: Modifier = Modifier |
the |
title: (@Composable () -> Unit)? = null |
optional title to be placed above |
subtitle: (@Composable () -> Unit)? = null |
|
header: (@Composable () -> Unit)? = null |
optional header image to be placed at the top of the card. This image should typically fill the max width available, for example using |
leadingIcon: (@Composable () -> Unit)? = null |
optional leading icon to be placed before |
trailingIcon: (@Composable () -> Unit)? = null |
optional trailing icon to be placed after |
shape: Shape = CardDefaults.shape |
the |
color: Color = GlimmerTheme.colors.surface |
background color of this card |
contentColor: Color = calculateContentColor(color) |
content color used by components inside |
contentPadding: PaddingValues = CardDefaults.contentPadding |
the spacing values to apply internally between the container and the content. Note that there is additional padding applied around the content / text / icons inside a card, this only affects the outermost content padding. |
interactionSource: MutableInteractionSource? = null |
an optional hoisted |
content: @Composable () -> Unit |
the main content / body text to display inside this card. This is recommended to be limited to 10 lines of text. |