TextKt

Added in 1.3.0-alpha05

public final class TextKt


Summary

Public methods

static final @NonNull LayoutElementBuilders.LayoutElement
text(
    @NonNull MaterialScope receiver,
    @NonNull TypeBuilders.StringProp text,
    @NonNull TypeBuilders.StringLayoutConstraint stringLayoutConstraint,
    int typography,
    @NonNull ColorBuilders.ColorProp color,
    boolean italic,
    boolean underline,
    boolean scalable,
    int maxLines,
    int multilineAlignment,
    int overflow,
    @NonNull ModifiersBuilders.Modifiers modifiers
)

ProtoLayout component that represents text object holding any information.

Public methods

public static final @NonNull LayoutElementBuilders.LayoutElement text(
    @NonNull MaterialScope receiver,
    @NonNull TypeBuilders.StringProp text,
    @NonNull TypeBuilders.StringLayoutConstraint stringLayoutConstraint,
    int typography,
    @NonNull ColorBuilders.ColorProp color,
    boolean italic,
    boolean underline,
    boolean scalable,
    int maxLines,
    int multilineAlignment,
    int overflow,
    @NonNull ModifiersBuilders.Modifiers 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.prop
import androidx.wear.protolayout.material3.text

materialScope(context, deviceConfiguration) {
        text(text = "Hello Material3".prop(), typography = Typography.DISPLAY_LARGE)
    }
import androidx.wear.protolayout.TypeBuilders.StringLayoutConstraint
import androidx.wear.protolayout.TypeBuilders.StringProp
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

materialScope(context, deviceConfiguration) {
        text(
            text =
                StringProp.Builder("Static")
                    .setDynamicValue(DynamicString.constant("Dynamic"))
                    .build(),
            stringLayoutConstraint = StringLayoutConstraint.Builder("Constraint").build(),
            typography = Typography.DISPLAY_LARGE,
            color = colorScheme.tertiary,
            underline = true,
            maxLines = 5
        )
    }
Parameters
@NonNull TypeBuilders.StringProp text

The text content for this component.

@NonNull TypeBuilders.StringLayoutConstraint stringLayoutConstraint

The layout constraints used to correctly measure Text view size and align text when text has dynamic value.

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 ColorBuilders.ColorProp 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 ModifiersBuilders.Modifiers modifiers

The additional Modifiers for this text.