TextKt

Added in 1.3.0-alpha08

public final class TextKt


Summary

Public methods

static final @NonNull LayoutElementBuilders.LayoutElement
text(
    @NonNull MaterialScope receiver,
    @NonNull LayoutString text,
    @NonNull LayoutModifier modifiers,
    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
)

ProtoLayout component that represents text object holding any information.

Public methods

public static final @NonNull LayoutElementBuilders.LayoutElement text(
    @NonNull MaterialScope receiver,
    @NonNull LayoutString text,
    @NonNull LayoutModifier modifiers,
    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
)

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.

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
        )
    }
Parameters
@NonNull LayoutString text

The text content for this component.

@NonNull LayoutModifier modifiers

Modifiers to set to this element.

int typography

The typography from Typography to be applied to this text. This will have predefined default value specified by each components that uses this text, to achieve the recommended look.

@NonNull LayoutColor color

The color to be applied to this text. It is recommended to use predefined default styles created by each component or getColorProp(token).

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 (FontSetting.weight, FontSetting.width and FontSetting.roundness.