@UnstableApi
public final class SpanUtil


Utility methods for Android span styling.

Summary

Public methods

static void
addInheritedRelativeSizeSpan(
    Spannable spannable,
    float size,
    int start,
    int end,
    int spanFlags
)

Modifies the size of the text between start and end relative to any existing RelativeSizeSpan instances which cover at least the same range.

static void
addOrReplaceSpan(
    Spannable spannable,
    Object span,
    int start,
    int end,
    int spanFlags
)

Adds span to spannable between start and end, removing any existing spans of the same type and with the same indices and flags.

Public methods

addInheritedRelativeSizeSpan

public static void addInheritedRelativeSizeSpan(
    Spannable spannable,
    float size,
    int start,
    int end,
    int spanFlags
)

Modifies the size of the text between start and end relative to any existing RelativeSizeSpan instances which cover at least the same range.

RelativeSizeSpan instances which only cover a part of the text between start and end are ignored.

A new RelativeSizeSpan instance is added between start and end with its sizeChange value computed by modifying the size parameter by the sizeChange of RelativeSizeSpan instances covering between start and end.

RelativeSizeSpan instances with the same start, end, and spanFlags are removed.

Parameters
Spannable spannable

The Spannable to add the RelativeSizeSpan to.

float size

The fraction to modify the text size by.

int start

The start index to add the new span at.

int end

The end index to add the new span at.

int spanFlags

The flags to pass to setSpan.

addOrReplaceSpan

public static void addOrReplaceSpan(
    Spannable spannable,
    Object span,
    int start,
    int end,
    int spanFlags
)

Adds span to spannable between start and end, removing any existing spans of the same type and with the same indices and flags.

This is useful for types of spans that don't make sense to duplicate and where the evaluation order might have an unexpected impact on the final text, e.g. .

Parameters
Spannable spannable

The Spannable to add span to.

Object span

The span object to be added.

int start

The start index to add the new span at.

int end

The end index to add the new span at.

int spanFlags

The flags to pass to setSpan.