CardKt
public final class CardKt
Summary
Public methods
appCard
public static final @NonNull LayoutElementBuilders.LayoutElement appCard(
@NonNull MaterialScope receiver,
@NonNull ModifiersBuilders.Clickable onClick,
@ExtensionFunctionType @NonNull Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> title,
@NonNull LayoutModifier modifier,
@ExtensionFunctionType Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> content,
@ExtensionFunctionType Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> avatar,
@ExtensionFunctionType Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> label,
@ExtensionFunctionType Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> time,
@NonNull DimensionBuilders.ContainerDimension height,
@NonNull ModifiersBuilders.Corner shape,
@NonNull CardColors colors,
@ExtensionFunctionType Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> backgroundContent,
@NonNull AppCardStyle style,
@NonNull ModifiersBuilders.Padding contentPadding
)
Opinionated ProtoLayout Material3 app card that offers up to 5 slots, usually text based.
Those are vertically stacked title and content, and additional side slot for a time.
The first row of the card has three slots:
-
a small optional image, such as
avatarImage
-
label, which is expected to be a short
text
-
time, end aligned.
The second row shows a title, this is expected to be a single row of start aligned text
.
The rest of the appCard
contains the content which should be text
.
The card's colors
default to using ColorScheme
from the MaterialScope
it's defined in, which defaults to dynamicColorScheme
, meaning that the colors follow system theme if available on device. If not, or switched off by user, uses fallback ColorScheme
defined in its MaterialScope
.
import androidx.wear.protolayout.DimensionBuilders.expand import androidx.wear.protolayout.material3.AppCardStyle import androidx.wear.protolayout.material3.CardDefaults.filledTonalCardColors import androidx.wear.protolayout.material3.appCard import androidx.wear.protolayout.material3.card import androidx.wear.protolayout.material3.materialScope import androidx.wear.protolayout.material3.primaryLayout import androidx.wear.protolayout.material3.text import androidx.wear.protolayout.modifiers.LayoutModifier import androidx.wear.protolayout.modifiers.clickable import androidx.wear.protolayout.modifiers.contentDescription import androidx.wear.protolayout.types.layoutString materialScope(context, deviceConfiguration) { primaryLayout( mainSlot = { appCard( onClick = clickable, modifier = LayoutModifier.contentDescription("App Card"), height = expand(), colors = filledTonalCardColors(), style = AppCardStyle.largeAppCardStyle(), title = { text("This is title of the app card".layoutString) }, time = { text("NOW".layoutString) }, label = { text("Label".layoutString) }, content = { text("Content of the Card!".layoutString) }, ) } ) }
Parameters | |
---|---|
@NonNull ModifiersBuilders.Clickable onClick |
Associated |
@ExtensionFunctionType @NonNull Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> title |
A slot for displaying the title of the card, expected to be one line of text. Uses |
@NonNull LayoutModifier modifier |
Modifiers to set to this element. It's highly recommended to set a content description using |
@ExtensionFunctionType Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> content |
The optional body content of the card. Uses |
@ExtensionFunctionType Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> avatar |
An optional slot in header for displaying small image, such as |
@ExtensionFunctionType Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> label |
An optional slot in header for displaying short, label text. Uses |
@ExtensionFunctionType Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> time |
An optional slot for displaying the time relevant to the contents of the card, expected to be a short piece of text. Uses |
@NonNull DimensionBuilders.ContainerDimension height |
The height of this card. It's highly recommended to leave this with default value as |
@NonNull ModifiersBuilders.Corner shape |
Defines the card's shape, in other words the corner radius for this card. If changing these to radius smaller than |
@NonNull CardColors colors |
The colors to be used for a background and inner content of this card. If the background image is also specified, the image will be laid out on top of the background color. In case of the fully opaque background image, then the background color will not be shown. Specified colors can be |
@ExtensionFunctionType Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> backgroundContent |
The background object to be used behind the content in the card. It is recommended to use the default styling that is automatically provided by only calling |
@NonNull AppCardStyle style |
The style which provides the attribute values required for constructing this title card and its inner content. It also provides default style for the inner content, that can be overridden by each content slot. |
@NonNull ModifiersBuilders.Padding contentPadding |
The inner padding used to prevent inner content from being too close to the card's edge. It's highly recommended to keep the default. |
card
public static final @NonNull LayoutElementBuilders.LayoutElement card(
@NonNull MaterialScope receiver,
@NonNull ModifiersBuilders.Clickable onClick,
@NonNull LayoutModifier modifier,
@NonNull DimensionBuilders.ContainerDimension width,
@NonNull DimensionBuilders.ContainerDimension height,
@ExtensionFunctionType Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> backgroundContent,
@NonNull ModifiersBuilders.Padding contentPadding,
@ExtensionFunctionType @NonNull Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> content
)
ProtoLayout Material3 clickable component card that offers a single slot to take any content.
It can be used as the container for more opinionated Card components that take specific content such as icons, images, primary label, secondary label, etc.
The Card is Rectangle shaped with some rounded corners by default. It is highly recommended to set its width and height to fill the available space, by expand
or weight
for optimal experience across different screen sizes.
It can be used for displaying any clickable container with additional data, text or graphics.
It is highly recommended to set its height to fill the available space, with expand
for optimal experience across different screen sizes.
import androidx.wear.protolayout.DimensionBuilders.expand import androidx.wear.protolayout.material3.backgroundImage import androidx.wear.protolayout.material3.card import androidx.wear.protolayout.material3.materialScope import androidx.wear.protolayout.material3.primaryLayout import androidx.wear.protolayout.material3.text import androidx.wear.protolayout.modifiers.LayoutModifier import androidx.wear.protolayout.modifiers.background import androidx.wear.protolayout.modifiers.clickable import androidx.wear.protolayout.modifiers.contentDescription import androidx.wear.protolayout.types.layoutString materialScope(context, deviceConfiguration) { primaryLayout( mainSlot = { card( onClick = clickable, modifier = LayoutModifier.contentDescription("Card with image background") .clickable(id = "card"), width = expand(), height = expand(), backgroundContent = { backgroundImage(protoLayoutResourceId = "id") } ) { text("Content of the Card!".layoutString) } } ) }
Parameters | |
---|---|
@NonNull ModifiersBuilders.Clickable onClick |
Associated |
@NonNull LayoutModifier modifier |
Modifiers to set to this element. It's highly recommended to set a content description using |
@NonNull DimensionBuilders.ContainerDimension width |
The width of this card. It's highly recommended to set this to |
@NonNull DimensionBuilders.ContainerDimension height |
The height of this card. It's highly recommended to set this to |
@ExtensionFunctionType Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> backgroundContent |
The background object to be used behind the content in the card. It is recommended to use the default styling that is automatically provided by only calling |
@NonNull ModifiersBuilders.Padding contentPadding |
The inner padding used to prevent inner content from being too close to the card's edge. It's highly recommended to keep the default. |
@ExtensionFunctionType @NonNull Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> content |
The inner content to be put inside of this card. |
graphicDataCard
public static final @NonNull LayoutElementBuilders.LayoutElement graphicDataCard(
@NonNull MaterialScope receiver,
@NonNull ModifiersBuilders.Clickable onClick,
@ExtensionFunctionType @NonNull Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> graphic,
@ExtensionFunctionType @NonNull Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> title,
@NonNull LayoutModifier modifier,
@ExtensionFunctionType Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> content,
@NonNull DimensionBuilders.ContainerDimension height,
@NonNull ModifiersBuilders.Corner shape,
@NonNull CardColors colors,
@NonNull GraphicDataCardStyle style,
int horizontalAlignment,
@NonNull ModifiersBuilders.Padding contentPadding
)
Opinionated ProtoLayout Material3 graphic data card that offers a slot for graphic data such as progress indicator and up to 2 vertically stacked slots, usually for textual description.
It is highly recommended to set its height to fill the available space, with expand
for optimal experience across different screen sizes.
The card's colors
default to using ColorScheme
from the MaterialScope
it's defined in, which defaults to dynamicColorScheme
, meaning that the colors follow system theme if available on device. If not, or switched off by user, uses fallback ColorScheme
defined in its MaterialScope
.
import androidx.wear.protolayout.DimensionBuilders.expand import androidx.wear.protolayout.material3.CardDefaults.filledVariantCardColors import androidx.wear.protolayout.material3.CircularProgressIndicatorDefaults.filledTonalProgressIndicatorColors import androidx.wear.protolayout.material3.GraphicDataCardStyle.Companion.largeGraphicDataCardStyle import androidx.wear.protolayout.material3.graphicDataCard import androidx.wear.protolayout.material3.icon import androidx.wear.protolayout.material3.materialScope import androidx.wear.protolayout.material3.primaryLayout import androidx.wear.protolayout.material3.segmentedCircularProgressIndicator import androidx.wear.protolayout.material3.text import androidx.wear.protolayout.modifiers.LayoutModifier import androidx.wear.protolayout.modifiers.clickable import androidx.wear.protolayout.modifiers.contentDescription import androidx.wear.protolayout.types.layoutString materialScope(context, deviceConfiguration) { primaryLayout( mainSlot = { graphicDataCard( onClick = clickable, modifier = LayoutModifier.contentDescription("Data Card with graphic"), height = expand(), colors = filledVariantCardColors(), style = largeGraphicDataCardStyle(), title = { text("1,234".layoutString) }, content = { icon("steps") }, graphic = { segmentedCircularProgressIndicator( segmentCount = 5, staticProgress = 0.5F, colors = filledTonalProgressIndicatorColors(), ) }, ) } ) }
Parameters | |
---|---|
@NonNull ModifiersBuilders.Clickable onClick |
Associated |
@ExtensionFunctionType @NonNull Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> graphic |
A slot for displaying graphic data, such as |
@ExtensionFunctionType @NonNull Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> title |
A slot for displaying the title of the card, expected to be one line of text. Uses |
@NonNull LayoutModifier modifier |
Modifiers to set to this element. It's highly recommended to set a content description using |
@ExtensionFunctionType Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> content |
The optional body content of the card. Uses |
@NonNull DimensionBuilders.ContainerDimension height |
The width of this card. It's highly recommended to set this to |
@NonNull ModifiersBuilders.Corner shape |
Defines the card's shape, in other words the corner radius for this card. If changing these to radius smaller than |
@NonNull CardColors colors |
The colors to be used for a background and inner content of this card. Specified colors can be |
@NonNull GraphicDataCardStyle style |
The style which provides the attribute values required for constructing this data card and its inner content. It also provides default style for the inner content, that can be overridden by each content slot. It is highly recommended to use one of |
int horizontalAlignment |
The horizontal placement of the |
@NonNull ModifiersBuilders.Padding contentPadding |
The inner padding used to prevent inner content from being too close to the card's edge. It's highly recommended to keep the default. |
iconDataCard
public static final @NonNull LayoutElementBuilders.LayoutElement iconDataCard(
@NonNull MaterialScope receiver,
@NonNull ModifiersBuilders.Clickable onClick,
@ExtensionFunctionType @NonNull Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> title,
@NonNull LayoutModifier modifier,
@ExtensionFunctionType Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> content,
@ExtensionFunctionType Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> secondaryIcon,
@NonNull DimensionBuilders.ContainerDimension width,
@NonNull DimensionBuilders.ContainerDimension height,
@NonNull ModifiersBuilders.Corner shape,
@NonNull CardColors colors,
@ExtensionFunctionType Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> backgroundContent,
@NonNull DataCardStyle style,
@NonNull TitleContentPlacementInDataCard titleContentPlacement,
@NonNull ModifiersBuilders.Padding contentPadding
)
Opinionated ProtoLayout Material3 data card that offers up to 3 vertically stacked slots, usually text or numeral based, with icon.
Slots can have multiple placements, depending on their presence and titleContentPlacement
:
-
If
secondaryIcon
are set, it will be placed first whentitleContentPlacement
is set toTitleContentPlacementInDataCard.Bottom
, or last iftitleContentPlacement
is set toTitleContentPlacementInDataCard.Top
. -
If
secondaryIcon
is not set, thistextDataCard
is considered ascompact
data card, with title and content only.
This card works well in buttonGroup
with cards width
and height
set to expand
.
The card's colors
default to using ColorScheme
from the MaterialScope
it's defined in, which defaults to dynamicColorScheme
, meaning that the colors follow system theme if available on device. If not, or switched off by user, uses fallback ColorScheme
defined in its MaterialScope
.
import androidx.wear.protolayout.DimensionBuilders.expand import androidx.wear.protolayout.DimensionBuilders.weight import androidx.wear.protolayout.material3.CardDefaults.filledTonalCardColors import androidx.wear.protolayout.material3.CardDefaults.filledVariantCardColors import androidx.wear.protolayout.material3.DataCardStyle.Companion.extraLargeDataCardStyle import androidx.wear.protolayout.material3.DataCardStyle.Companion.largeCompactDataCardStyle import androidx.wear.protolayout.material3.button import androidx.wear.protolayout.material3.buttonGroup import androidx.wear.protolayout.material3.icon import androidx.wear.protolayout.material3.iconDataCard import androidx.wear.protolayout.material3.materialScope import androidx.wear.protolayout.material3.primaryLayout import androidx.wear.protolayout.material3.text import androidx.wear.protolayout.material3.textDataCard import androidx.wear.protolayout.modifiers.LayoutModifier import androidx.wear.protolayout.modifiers.clickable import androidx.wear.protolayout.modifiers.contentDescription import androidx.wear.protolayout.types.layoutString materialScope(context, deviceConfiguration) { primaryLayout( mainSlot = { buttonGroup { buttonGroupItem { textDataCard( onClick = clickable, modifier = LayoutModifier.contentDescription("Data Card with text"), width = weight(1f), height = expand(), colors = filledTonalCardColors(), style = extraLargeDataCardStyle(), title = { this.text("1km".layoutString) }, content = { this.text("Run".layoutString) }, secondaryText = { this.text("Nice!".layoutString) } ) } buttonGroupItem { iconDataCard( onClick = clickable, modifier = LayoutModifier.contentDescription("Data Card with icon"), width = weight(1f), height = expand(), colors = filledTonalCardColors(), style = extraLargeDataCardStyle(), title = { this.text("2km".layoutString) }, secondaryIcon = { icon("id") }, content = { this.text("Run".layoutString) }, ) } buttonGroupItem { textDataCard( onClick = clickable, modifier = LayoutModifier.contentDescription( "Compact Data Card without icon or secondary label" ), width = weight(3f), height = expand(), colors = filledVariantCardColors(), style = largeCompactDataCardStyle(), title = { this.text("10:30".layoutString) }, content = { this.text("PM".layoutString) }, ) } } } ) }
Parameters | |
---|---|
@NonNull ModifiersBuilders.Clickable onClick |
Associated |
@ExtensionFunctionType @NonNull Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> title |
A slot for displaying the title of the card, expected to be one line of text. Uses |
@NonNull LayoutModifier modifier |
Modifiers to set to this element. It's highly recommended to set a content description using |
@ExtensionFunctionType Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> content |
The optional body content of the card. Uses |
@ExtensionFunctionType Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> secondaryIcon |
An optional slot for displaying small icon, such as |
@NonNull DimensionBuilders.ContainerDimension width |
The width of this card. It's highly recommended to set this to |
@NonNull DimensionBuilders.ContainerDimension height |
The height of this card. It's highly recommended to set this to |
@NonNull ModifiersBuilders.Corner shape |
Defines the card's shape, in other words the corner radius for this card. If changing these to radius smaller than |
@NonNull CardColors colors |
The colors to be used for a background and inner content of this card. If the background image is also specified, the image will be laid out on top of the background color. In case of the fully opaque background image, then the background color will not be shown. Specified colors can be |
@ExtensionFunctionType Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> backgroundContent |
The background object to be used behind the content in the card. It is recommended to use the default styling that is automatically provided by only calling |
@NonNull DataCardStyle style |
The style which provides the attribute values required for constructing this data card and its inner content. It also provides default style for the inner content, that can be overridden by each content slot. It is highly recommended to use one of |
@NonNull TitleContentPlacementInDataCard titleContentPlacement |
The placement of the |
@NonNull ModifiersBuilders.Padding contentPadding |
The inner padding used to prevent inner content from being too close to the card's edge. It's highly recommended to keep the default. |
textDataCard
public static final @NonNull LayoutElementBuilders.LayoutElement textDataCard(
@NonNull MaterialScope receiver,
@NonNull ModifiersBuilders.Clickable onClick,
@ExtensionFunctionType @NonNull Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> title,
@NonNull LayoutModifier modifier,
@ExtensionFunctionType Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> content,
@ExtensionFunctionType Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> secondaryText,
@NonNull DimensionBuilders.ContainerDimension width,
@NonNull DimensionBuilders.ContainerDimension height,
@NonNull ModifiersBuilders.Corner shape,
@NonNull CardColors colors,
@ExtensionFunctionType Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> backgroundContent,
@NonNull DataCardStyle style,
@NonNull ModifiersBuilders.Padding contentPadding
)
Opinionated ProtoLayout Material3 data card that offers up to 3 vertically stacked slots, usually text or numeral based.
This card works well in buttonGroup
with cards width
and height
is set to expand
.
The card's colors
default to using ColorScheme
from the MaterialScope
it's defined in, which defaults to dynamicColorScheme
, meaning that the colors follow system theme if available on device. If not, or switched off by user, uses fallback ColorScheme
defined in its MaterialScope
.
import androidx.wear.protolayout.DimensionBuilders.expand import androidx.wear.protolayout.DimensionBuilders.weight import androidx.wear.protolayout.material3.CardDefaults.filledTonalCardColors import androidx.wear.protolayout.material3.CardDefaults.filledVariantCardColors import androidx.wear.protolayout.material3.DataCardStyle.Companion.extraLargeDataCardStyle import androidx.wear.protolayout.material3.DataCardStyle.Companion.largeCompactDataCardStyle import androidx.wear.protolayout.material3.button import androidx.wear.protolayout.material3.buttonGroup import androidx.wear.protolayout.material3.icon import androidx.wear.protolayout.material3.iconDataCard import androidx.wear.protolayout.material3.materialScope import androidx.wear.protolayout.material3.primaryLayout import androidx.wear.protolayout.material3.text import androidx.wear.protolayout.material3.textDataCard import androidx.wear.protolayout.modifiers.LayoutModifier import androidx.wear.protolayout.modifiers.clickable import androidx.wear.protolayout.modifiers.contentDescription import androidx.wear.protolayout.types.layoutString materialScope(context, deviceConfiguration) { primaryLayout( mainSlot = { buttonGroup { buttonGroupItem { textDataCard( onClick = clickable, modifier = LayoutModifier.contentDescription("Data Card with text"), width = weight(1f), height = expand(), colors = filledTonalCardColors(), style = extraLargeDataCardStyle(), title = { this.text("1km".layoutString) }, content = { this.text("Run".layoutString) }, secondaryText = { this.text("Nice!".layoutString) } ) } buttonGroupItem { iconDataCard( onClick = clickable, modifier = LayoutModifier.contentDescription("Data Card with icon"), width = weight(1f), height = expand(), colors = filledTonalCardColors(), style = extraLargeDataCardStyle(), title = { this.text("2km".layoutString) }, secondaryIcon = { icon("id") }, content = { this.text("Run".layoutString) }, ) } buttonGroupItem { textDataCard( onClick = clickable, modifier = LayoutModifier.contentDescription( "Compact Data Card without icon or secondary label" ), width = weight(3f), height = expand(), colors = filledVariantCardColors(), style = largeCompactDataCardStyle(), title = { this.text("10:30".layoutString) }, content = { this.text("PM".layoutString) }, ) } } } ) }
Parameters | |
---|---|
@NonNull ModifiersBuilders.Clickable onClick |
Associated |
@ExtensionFunctionType @NonNull Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> title |
A slot for displaying the title of the card, expected to be one line of text. Uses |
@NonNull LayoutModifier modifier |
Modifiers to set to this element. It's highly recommended to set a content description using |
@ExtensionFunctionType Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> content |
The optional body content of the card. Uses |
@ExtensionFunctionType Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> secondaryText |
An optional slot for displaying short, secondary text. Uses |
@NonNull DimensionBuilders.ContainerDimension width |
The width of this card. It's highly recommended to set this to |
@NonNull DimensionBuilders.ContainerDimension height |
The height of this card. It's highly recommended to set this to |
@NonNull ModifiersBuilders.Corner shape |
Defines the card's shape, in other words the corner radius for this card. If changing these to radius smaller than |
@NonNull CardColors colors |
The colors to be used for a background and inner content of this card. If the background image is also specified, the image will be laid out on top of the background color. In case of the fully opaque background image, then the background color will not be shown. Specified colors can be |
@ExtensionFunctionType Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> backgroundContent |
The background object to be used behind the content in the card. It is recommended to use the default styling that is automatically provided by only calling |
@NonNull DataCardStyle style |
The style which provides the attribute values required for constructing this data card and its inner content. It also provides default style for the inner content, that can be overridden by each content slot. It is highly recommended to use one of |
@NonNull ModifiersBuilders.Padding contentPadding |
The inner padding used to prevent inner content from being too close to the card's edge. It's highly recommended to keep the default. |
titleCard
public static final @NonNull LayoutElementBuilders.LayoutElement titleCard(
@NonNull MaterialScope receiver,
@NonNull ModifiersBuilders.Clickable onClick,
@ExtensionFunctionType @NonNull Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> title,
@NonNull LayoutModifier modifier,
@ExtensionFunctionType Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> content,
@ExtensionFunctionType Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> time,
@NonNull DimensionBuilders.ContainerDimension height,
@NonNull ModifiersBuilders.Corner shape,
@NonNull CardColors colors,
@ExtensionFunctionType Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> backgroundContent,
@NonNull TitleCardStyle style,
@NonNull ModifiersBuilders.Padding contentPadding,
int horizontalAlignment
)
Opinionated ProtoLayout Material3 title card that offers 1 to 3 slots, usually text based.
Those are vertically stacked title and content, and additional side slot for a time.
It is highly recommended to set its height to fill the available space, with expand
for optimal experience across different screen sizes.
The card's colors
default to using ColorScheme
from the MaterialScope
it's defined in, which defaults to dynamicColorScheme
, meaning that the colors follow system theme if available on device. If not, or switched off by user, uses fallback ColorScheme
defined in its MaterialScope
.
import androidx.wear.protolayout.DimensionBuilders.expand import androidx.wear.protolayout.material3.CardDefaults.filledVariantCardColors import androidx.wear.protolayout.material3.TitleCardStyle.Companion.largeTitleCardStyle import androidx.wear.protolayout.material3.card import androidx.wear.protolayout.material3.materialScope import androidx.wear.protolayout.material3.primaryLayout import androidx.wear.protolayout.material3.text import androidx.wear.protolayout.material3.titleCard import androidx.wear.protolayout.modifiers.LayoutModifier import androidx.wear.protolayout.modifiers.clickable import androidx.wear.protolayout.modifiers.contentDescription import androidx.wear.protolayout.types.layoutString materialScope(context, deviceConfiguration) { primaryLayout( mainSlot = { titleCard( onClick = clickable, modifier = LayoutModifier.contentDescription("Title Card"), height = expand(), colors = filledVariantCardColors(), style = largeTitleCardStyle(), title = { text("This is title of the title card".layoutString) }, time = { text("NOW".layoutString) }, content = { text("Content of the Card!".layoutString) } ) } ) }
Parameters | |
---|---|
@NonNull ModifiersBuilders.Clickable onClick |
Associated |
@ExtensionFunctionType @NonNull Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> title |
A slot for displaying the title of the card, expected to be one or two lines of text. Uses |
@NonNull LayoutModifier modifier |
Modifiers to set to this element. It's highly recommended to set a content description using |
@ExtensionFunctionType Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> content |
The optional body content of the card. Uses |
@ExtensionFunctionType Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> time |
An optional slot for displaying the time relevant to the contents of the card, expected to be a short piece of text. Uses |
@NonNull DimensionBuilders.ContainerDimension height |
The height of this card. It's highly recommended to set this to |
@NonNull ModifiersBuilders.Corner shape |
Defines the card's shape, in other words the corner radius for this card. If changing these to radius smaller than |
@NonNull CardColors colors |
The colors to be used for a background and inner content of this card. If the background image is also specified, the image will be laid out on top of the background color. In case of the fully opaque background image, then the background color will not be shown. Specified colors can be |
@ExtensionFunctionType Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> backgroundContent |
The background object to be used behind the content in the card. It is recommended to use the default styling that is automatically provided by only calling |
@NonNull TitleCardStyle style |
The style which provides the attribute values required for constructing this title card and its inner content. It also provides default style for the inner content, that can be overridden by each content slot. |
@NonNull ModifiersBuilders.Padding contentPadding |
The inner padding used to prevent inner content from being too close to the card's edge. It's highly recommended to keep the default. |
int horizontalAlignment |
The horizontal alignment of |