@UnstableApi
class SpanUtil


Utility methods for Android span styling.

Summary

Public functions

java-static Unit
addInheritedRelativeSizeSpan(
    spannable: Spannable!,
    size: Float,
    start: Int,
    end: Int,
    spanFlags: Int
)

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

java-static Unit
addOrReplaceSpan(
    spannable: Spannable!,
    span: Any!,
    start: Int,
    end: Int,
    spanFlags: Int
)

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

Public functions

addInheritedRelativeSizeSpan

java-static fun addInheritedRelativeSizeSpan(
    spannable: Spannable!,
    size: Float,
    start: Int,
    end: Int,
    spanFlags: Int
): Unit

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.

size: Float

The fraction to modify the text size by.

start: Int

The start index to add the new span at.

end: Int

The end index to add the new span at.

spanFlags: Int

The flags to pass to setSpan.

addOrReplaceSpan

java-static fun addOrReplaceSpan(
    spannable: Spannable!,
    span: Any!,
    start: Int,
    end: Int,
    spanFlags: Int
): Unit

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.

span: Any!

The span object to be added.

start: Int

The start index to add the new span at.

end: Int

The end index to add the new span at.

spanFlags: Int

The flags to pass to setSpan.