TextKt

Added in 1.3.0-alpha06

public final class TextKt


Summary

Public methods

static final @NonNull LayoutElementBuilders.LayoutElement
text(
    @NonNull MaterialScope receiver,
    @NonNull LayoutString text,
    int typography,
    @NonNull LayoutColor color,
    boolean italic,
    boolean underline,
    boolean scalable,
    int maxLines,
    int multilineAlignment,
    int overflow,
    @NonNull LayoutModifier modifiers
)

ProtoLayout component that represents text object holding any information.

Public methods

public static final @NonNull LayoutElementBuilders.LayoutElement text(
    @NonNull MaterialScope receiver,
    @NonNull LayoutString text,
    int typography,
    @NonNull LayoutColor color,
    boolean italic,
    boolean underline,
    boolean scalable,
    int maxLines,
    int multilineAlignment,
    int overflow,
    @NonNull LayoutModifier modifiers
)

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.

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 multilineAlignment

The horizontal alignment of the multiple lines of text.

int overflow

The overflow strategy when text doesn't have enough space to be shown.

@NonNull LayoutModifier modifiers

Modifiers to set to this element.