TextKt
public final class TextKt
Summary
Public methods |
|
|---|---|
static final @NonNull LayoutElementBuilders.LayoutElement |
text(ProtoLayout component that represents text object holding any information. |
Public methods
text
public static final @NonNull LayoutElementBuilders.LayoutElement text(
@NonNull MaterialScope receiver,
@NonNull LayoutString text,
@NonNull LayoutModifier modifier,
int typography,
@NonNull LayoutColor color,
boolean italic,
boolean underline,
boolean scalable,
int maxLines,
int alignment,
int overflow,
@RequiresSchemaVersion(major = 1, minor = 400) @NonNull List<@NonNull LayoutElementBuilders.FontSetting> settings,
@NonNull List<@NonNull Float> incrementsForTypographySize
)
ProtoLayout component that represents text object holding any information.
There are pre-defined typography styles that can be obtained from Materials token system in Typography.
This text, when added to the titleSlot, bottomSlot and labelForBottomSlot in primaryLayout, is considered as important for accessibility automatically and gets read out by the screen reader even without content description provided in the modifier. This behavior can be removed with LayoutModifier.clearSemantics if not desired. In all other places, this text is considered as not important for accessibility by default unless content description is specifically provided in the modifier.
import androidx.wear.protolayout.material3.Typography import androidx.wear.protolayout.material3.materialScope import androidx.wear.protolayout.material3.text import androidx.wear.protolayout.types.layoutString materialScope(context, deviceConfiguration) { text(text = "Hello Material3".layoutString, typography = Typography.DISPLAY_LARGE) }
import androidx.wear.protolayout.expression.DynamicBuilders.DynamicString import androidx.wear.protolayout.material3.Typography import androidx.wear.protolayout.material3.materialScope import androidx.wear.protolayout.material3.text import androidx.wear.protolayout.types.LayoutString import androidx.wear.protolayout.types.asLayoutConstraint materialScope(context, deviceConfiguration) { this.text( text = LayoutString( "Static", DynamicString.constant("Dynamic"), "LongestConstraint".asLayoutConstraint(), ), typography = Typography.DISPLAY_LARGE, color = colorScheme.tertiary, underline = true, maxLines = 5, ) }
import androidx.wear.protolayout.material3.Typography import androidx.wear.protolayout.material3.materialScope import androidx.wear.protolayout.material3.text import androidx.wear.protolayout.types.layoutString materialScope(context, deviceConfiguration) { text( text = "Hello Material3".layoutString, typography = Typography.DISPLAY_LARGE, incrementsForTypographySize = listOf(-4f, -2f, 2f), ) }
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.clearSemantics import androidx.wear.protolayout.types.layoutString materialScope(context, deviceConfiguration) { primaryLayout( titleSlot = { text("App title".layoutString, modifier = LayoutModifier.clearSemantics()) }, mainSlot = { text("Main content".layoutString) }, bottomSlot = { text("Bottom slot".layoutString, modifier = LayoutModifier.clearSemantics()) }, labelForBottomSlot = { text("Bottom label".layoutString, modifier = LayoutModifier.clearSemantics()) }, ) }
| Parameters | |
|---|---|
@NonNull LayoutString text |
The text content for this component. |
@NonNull LayoutModifier modifier |
Modifiers to set to this element. |
int typography |
The typography from |
@NonNull LayoutColor color |
The color to be applied to this text. It is recommended to use predefined default styles created by each component or |
boolean italic |
Whether text should be displayed as italic. |
boolean underline |
Whether text should be displayed as underlined. |
boolean scalable |
Whether text should scale with the user font size. |
int maxLines |
The maximum number of lines that text can occupy. |
int alignment |
The horizontal alignment of the multiple lines of text or one line of text when text overflows. |
int overflow |
The overflow strategy when text doesn't have enough space to be shown. |
@RequiresSchemaVersion(major = 1, minor = 400) @NonNull List<@NonNull LayoutElementBuilders.FontSetting> settings |
The collection of font settings to be applied. If more than one Setting with the same axis tag is specified, the first one will be used. Supported settings depend on the font used and renderer version. Each default typography will apply appropriate default setting axes for it ( |
@NonNull List<@NonNull Float> incrementsForTypographySize |
The collection increments for the given |