LayoutElementBuilders.Text.Builder


public final class LayoutElementBuilders.Text.Builder


Builder for Text.

Summary

Public constructors

Creates an instance of Builder.

Public methods

@NonNull LayoutElementBuilders.Text

Builds an instance with values accumulated in this Builder.

@NonNull LayoutElementBuilders.Text.Builder

Sets the style of font to use (size, bold etc).

@NonNull LayoutElementBuilders.Text.Builder
@RequiresSchemaVersion(major = 1, minor = 200)
setLayoutConstraintsForDynamicText(
    @NonNull TypeBuilders.StringLayoutConstraint stringLayoutConstraint
)

Sets the bounding constraints for the layout affected by the dynamic value from setText}.

@NonNull LayoutElementBuilders.Text.Builder
@RequiresSchemaVersion(major = 1, minor = 0)
setLineHeight(@NonNull DimensionBuilders.SpProp lineHeight)

Sets the explicit height between lines of text.

@NonNull LayoutElementBuilders.Text.Builder
@RequiresSchemaVersion(major = 1, minor = 200)
@ProtoLayoutExperimental
setMarqueeIterations(@IntRange(from = "-1") int marqueeIterations)

Sets the number of times to repeat the Marquee animation.

@NonNull LayoutElementBuilders.Text.Builder
setMaxLines(@IntRange(from = 1) int maxLines)

Sets the maximum number of lines that can be represented by the Text element.

@NonNull LayoutElementBuilders.Text.Builder
@RequiresSchemaVersion(major = 1, minor = 0)
setMaxLines(@NonNull TypeBuilders.Int32Prop maxLines)

Sets the maximum number of lines that can be represented by the Text element.

@NonNull LayoutElementBuilders.Text.Builder

Sets androidx.wear.protolayout.ModifiersBuilders.Modifiers for this element.

@NonNull LayoutElementBuilders.Text.Builder
@RequiresSchemaVersion(major = 1, minor = 0)
setMultilineAlignment(int multilineAlignment)

Sets alignment of the text within its bounds.

@NonNull LayoutElementBuilders.Text.Builder
@RequiresSchemaVersion(major = 1, minor = 0)
setMultilineAlignment(
    @NonNull LayoutElementBuilders.TextAlignmentProp multilineAlignment
)

Sets alignment of the text within its bounds.

@NonNull LayoutElementBuilders.Text.Builder
@RequiresSchemaVersion(major = 1, minor = 0)
setOverflow(int overflow)

Sets how to handle text which overflows the bound of the Text element.

@NonNull LayoutElementBuilders.Text.Builder

Sets how to handle text which overflows the bound of the Text element.

@NonNull LayoutElementBuilders.Text.Builder
@RequiresSchemaVersion(major = 1, minor = 0)
setText(@NonNull String text)

Sets the static text to render.

@NonNull LayoutElementBuilders.Text.Builder

Sets the text to render.

Public constructors

Builder

Added in 1.0.0
public Builder()

Creates an instance of Builder.

Public methods

build

Added in 1.0.0
public @NonNull LayoutElementBuilders.Text build()

Builds an instance with values accumulated in this Builder.

setFontStyle

Added in 1.0.0
@RequiresSchemaVersion(major = 1, minor = 0)
public @NonNull LayoutElementBuilders.Text.Builder setFontStyle(@NonNull LayoutElementBuilders.FontStyle fontStyle)

Sets the style of font to use (size, bold etc). If not specified, defaults to the platform's default body font.

setLayoutConstraintsForDynamicText

Added in 1.0.0
@RequiresSchemaVersion(major = 1, minor = 200)
public @NonNull LayoutElementBuilders.Text.Builder setLayoutConstraintsForDynamicText(
    @NonNull TypeBuilders.StringLayoutConstraint stringLayoutConstraint
)

Sets the bounding constraints for the layout affected by the dynamic value from setText}.

setLineHeight

Added in 1.0.0
@RequiresSchemaVersion(major = 1, minor = 0)
public @NonNull LayoutElementBuilders.Text.Builder setLineHeight(@NonNull DimensionBuilders.SpProp lineHeight)

Sets the explicit height between lines of text. This is equivalent to the vertical distance between subsequent baselines. If not specified, defaults the font's recommended interline spacing.

setMarqueeIterations

Added in 1.0.0
@RequiresSchemaVersion(major = 1, minor = 200)
@ProtoLayoutExperimental
public @NonNull LayoutElementBuilders.Text.Builder setMarqueeIterations(@IntRange(from = "-1") int marqueeIterations)

Sets the number of times to repeat the Marquee animation. Only applies when overflow is TEXT_OVERFLOW_MARQUEE. Set to -1 to repeat indefinitely. Defaults to repeat indefinitely.

setMaxLines

Added in 1.0.0
public @NonNull LayoutElementBuilders.Text.Builder setMaxLines(@IntRange(from = 1) int maxLines)

Sets the maximum number of lines that can be represented by the Text element. If not defined, the Text element will be treated as a single-line element.

setMaxLines

Added in 1.0.0
@RequiresSchemaVersion(major = 1, minor = 0)
public @NonNull LayoutElementBuilders.Text.Builder setMaxLines(@NonNull TypeBuilders.Int32Prop maxLines)

Sets the maximum number of lines that can be represented by the Text element. If not defined, the Text element will be treated as a single-line element.

setMultilineAlignment

Added in 1.0.0
@RequiresSchemaVersion(major = 1, minor = 0)
public @NonNull LayoutElementBuilders.Text.Builder setMultilineAlignment(int multilineAlignment)

Sets alignment of the text within its bounds. Note that a Text element will size itself to wrap its contents, so this option is meaningless for single-line text (for that, use alignment of the outer container). For multi-line text, however, this will set the alignment of lines relative to the Text element bounds. If not defined, defaults to TEXT_ALIGN_CENTER.

setMultilineAlignment

Added in 1.0.0
@RequiresSchemaVersion(major = 1, minor = 0)
public @NonNull LayoutElementBuilders.Text.Builder setMultilineAlignment(
    @NonNull LayoutElementBuilders.TextAlignmentProp multilineAlignment
)

Sets alignment of the text within its bounds. Note that a Text element will size itself to wrap its contents, so this option is meaningless for single-line text (for that, use alignment of the outer container). For multi-line text, however, this will set the alignment of lines relative to the Text element bounds. If not defined, defaults to TEXT_ALIGN_CENTER.

setOverflow

Added in 1.0.0
@RequiresSchemaVersion(major = 1, minor = 0)
public @NonNull LayoutElementBuilders.Text.Builder setOverflow(int overflow)

Sets how to handle text which overflows the bound of the Text element. A Text element will grow as large as possible inside its parent container (while still respecting max_lines); if it cannot grow large enough to render all of its text, the text which cannot fit inside its container will be truncated. If not defined, defaults to TEXT_OVERFLOW_TRUNCATE.

setOverflow

Added in 1.0.0
@RequiresSchemaVersion(major = 1, minor = 0)
public @NonNull LayoutElementBuilders.Text.Builder setOverflow(@NonNull LayoutElementBuilders.TextOverflowProp overflow)

Sets how to handle text which overflows the bound of the Text element. A Text element will grow as large as possible inside its parent container (while still respecting max_lines); if it cannot grow large enough to render all of its text, the text which cannot fit inside its container will be truncated. If not defined, defaults to TEXT_OVERFLOW_TRUNCATE.

setText

Added in 1.0.0
@RequiresSchemaVersion(major = 1, minor = 0)
public @NonNull LayoutElementBuilders.Text.Builder setText(@NonNull String text)

Sets the static text to render.

setText

Added in 1.0.0
@RequiresSchemaVersion(major = 1, minor = 0)
public @NonNull LayoutElementBuilders.Text.Builder setText(@NonNull TypeBuilders.StringProp text)

Sets the text to render.

While this field is statically accessible from 1.0, it's only bindable since version 1.2 and renderers supporting version 1.2 will use the dynamic value (if set).

When using a dynamic value, make sure to specify the bounding constraints for the affected layout element through setLayoutConstraintsForDynamicText(StringLayoutConstraint) otherwise build() fails.