LayoutElementBuilders.Spannable

public final class LayoutElementBuilders.Spannable implements LayoutElementBuilders.LayoutElement


A container of Span elements. Currently, this only supports Text elements, where each individual Span can have different styling applied to it but the resulting text will flow naturally. This allows sections of a paragraph of text to have different styling applied to it, for example, making one or two words bold or italic.

Summary

Public constructors

Public methods

@Nullable DimensionBuilders.SpProp

Gets the explicit height between lines of text.

@Nullable TypeBuilders.Int32Prop

Gets the maximum number of lines that can be represented by the Spannable element.

@Nullable ModifiersBuilders.Modifiers

Gets androidx.wear.tiles.ModifiersBuilders.Modifiers for this element.

@Nullable LayoutElementBuilders.HorizontalAlignmentProp

Gets alignment of the Spannable content within its bounds.

@Nullable LayoutElementBuilders.TextOverflowProp

Gets how to handle content which overflows the bound of the Spannable element.

@NonNull List<LayoutElementBuilders.Span>

Gets the Span elements that form this Spannable.

Extension functions

final void

Clear all spans from this text.

final void
SpannableStringKt.set(
    Spannable receiver,
    int start,
    int end,
    Object span
)

Add span to the range startend of the text.

final void
SpannableStringKt.set(Spannable receiver, IntRange range, Object span)

Add span to the range of the text.

Public constructors

Spannable

public final Spannable()

Public methods

getLineHeight

public @Nullable DimensionBuilders.SpProp getLineHeight()

Gets 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. Intended for testing purposes only.

getMaxLines

public @Nullable TypeBuilders.Int32Prop getMaxLines()

Gets the maximum number of lines that can be represented by the Spannable element. If not defined, the Spannable element will be treated as a single-line element. Intended for testing purposes only.

getModifiers

public @Nullable ModifiersBuilders.Modifiers getModifiers()

Gets androidx.wear.tiles.ModifiersBuilders.Modifiers for this element. Intended for testing purposes only.

getMultilineAlignment

public @Nullable LayoutElementBuilders.HorizontalAlignmentProp getMultilineAlignment()

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

getOverflow

public @Nullable LayoutElementBuilders.TextOverflowProp getOverflow()

Gets how to handle content which overflows the bound of the Spannable element. A Spannable 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 content, the content which cannot fit inside its container will be truncated. If not defined, defaults to TEXT_OVERFLOW_TRUNCATE. Intended for testing purposes only.

getSpans

public @NonNull List<LayoutElementBuilders.SpangetSpans()

Gets the Span elements that form this Spannable. Intended for testing purposes only.

Extension functions

SpannableStringKt.clearSpans

public final void SpannableStringKt.clearSpans(Spannable receiver)

Clear all spans from this text.

SpannableStringKt.set

public final void SpannableStringKt.set(
    Spannable receiver,
    int start,
    int end,
    Object span
)

Add span to the range startend of the text.

val s = "Hello, World!".toSpannable()
s[0, 5] = UnderlineSpan()

Note: The end value is exclusive.

See also
setSpan

SpannableStringKt.set

public final void SpannableStringKt.set(Spannable receiver, IntRange range, Object span)

Add span to the range of the text.

val s = "Hello, World!".toSpannable()
s[0..5] = UnderlineSpan()

Note: The range end value is exclusive.

See also
setSpan