androidx.core.text


Interfaces

TextDirectionHeuristicCompat

Interface for objects that use a heuristic for guessing at the paragraph direction by examining text.

Classes

BidiFormatter

Utility class for formatting text for display in a potentially opposite-directionality context without garbling.

BidiFormatter.Builder

A class for building a BidiFormatter with non-default options.

HtmlCompat

Backwards compatible version of Html.

ICUCompat
PrecomputedTextCompat

A text which has the character metrics data.

PrecomputedTextCompat.Params

The information required for building PrecomputedTextCompat.

PrecomputedTextCompat.Params.Builder

A builder for creating Params.

TextDirectionHeuristicsCompat

Some objects that implement TextDirectionHeuristic.

TextUtilsCompat

Backwards compatible version of TextUtils.

Top-level functions summary

inline SpannedString

Builds new string by populating a newly created SpannableStringBuilder using the provided builderAction and then converting it to SpannedString.

Extension functions summary

inline SpannableStringBuilder
SpannableStringBuilder.backgroundColor(
    color: @ColorInt Int,
    builderAction: SpannableStringBuilder.() -> Unit
)

Wrap appended text in builderAction in a BackgroundColorSpan.

inline SpannableStringBuilder

Wrap appended text in builderAction in a bold StyleSpan.

inline Unit

Clear all spans from this text.

inline SpannableStringBuilder
SpannableStringBuilder.color(
    color: @ColorInt Int,
    builderAction: SpannableStringBuilder.() -> Unit
)

Wrap appended text in builderAction in a ForegroundColorSpan.

inline Array<T>
<T : Any> Spanned.getSpans(start: Int, end: Int)

Get all spans that are instance of T.

inline String

Html-encode the string.

inline SpannableStringBuilder

Wrap appended text in builderAction in span.

inline SpannableStringBuilder
SpannableStringBuilder.inSpans(
    vararg spans: Any,
    builderAction: SpannableStringBuilder.() -> Unit
)

Wrap appended text in builderAction in spans.

inline Boolean

Returns whether the given CharSequence contains only digits.

inline SpannableStringBuilder

Wrap appended text in builderAction in an italic StyleSpan.

inline Spanned
String.parseAsHtml(
    flags: Int,
    imageGetter: Html.ImageGetter?,
    tagHandler: Html.TagHandler?
)

Returns a Spanned from parsing this string as HTML.

inline SpannableStringBuilder
SpannableStringBuilder.scale(
    proportion: Float,
    builderAction: SpannableStringBuilder.() -> Unit
)

Wrap appended text in builderAction in a RelativeSizeSpan.

inline operator Unit
Spannable.set(range: IntRange, span: Any)

Add span to the range of the text.

inline operator Unit
Spannable.set(start: Int, end: Int, span: Any)

Add span to the range startend of the text.

inline SpannableStringBuilder

Wrap appended text in builderAction in a StrikethroughSpan.

inline SpannableStringBuilder

Wrap appended text in builderAction in a SubscriptSpan.

inline SpannableStringBuilder

Wrap appended text in builderAction in a SuperscriptSpan.

inline String
Spanned.toHtml(option: Int)

Returns a string of HTML from the spans in this Spanned.

inline Spannable

Returns a new Spannable from CharSequence, or the source itself if it is already an instance of SpannableString.

inline Spanned

Returns a new Spanned from CharSequence, or the source itself if it is already an instance of SpannedString.

inline Int

Returns the length that the specified CharSequence would have if spaces and ASCII control characters were trimmed from the start and end, as by String.trim.

inline SpannableStringBuilder

Wrap appended text in builderAction in an UnderlineSpan.

Extension properties summary

Int

Returns layout direction for a given locale.

Top-level functions

buildSpannedString

inline fun buildSpannedString(builderAction: SpannableStringBuilder.() -> Unit): SpannedString

Builds new string by populating a newly created SpannableStringBuilder using the provided builderAction and then converting it to SpannedString.

Extension functions

backgroundColor

inline fun SpannableStringBuilder.backgroundColor(
    color: @ColorInt Int,
    builderAction: SpannableStringBuilder.() -> Unit
): SpannableStringBuilder

Wrap appended text in builderAction in a BackgroundColorSpan.

See also
inSpans

bold

inline fun SpannableStringBuilder.bold(builderAction: SpannableStringBuilder.() -> Unit): SpannableStringBuilder

Wrap appended text in builderAction in a bold StyleSpan.

See also
inSpans

clearSpans

inline fun Spannable.clearSpans(): Unit

Clear all spans from this text.

color

inline fun SpannableStringBuilder.color(
    color: @ColorInt Int,
    builderAction: SpannableStringBuilder.() -> Unit
): SpannableStringBuilder

Wrap appended text in builderAction in a ForegroundColorSpan.

See also
inSpans

getSpans

inline fun <T : Any> Spanned.getSpans(start: Int = 0, end: Int = length): Array<T>

Get all spans that are instance of T.

htmlEncode

inline fun String.htmlEncode(): String

Html-encode the string.

See also
htmlEncode

inSpans

inline fun SpannableStringBuilder.inSpans(span: Any, builderAction: SpannableStringBuilder.() -> Unit): SpannableStringBuilder

Wrap appended text in builderAction in span.

Note: the span will only have the correct position if the builderAction only appends or replaces text. Inserting, deleting, or clearing the text will cause the span to be placed at an incorrect position.

inline fun SpannableStringBuilder.inSpans(
    vararg spans: Any,
    builderAction: SpannableStringBuilder.() -> Unit
): SpannableStringBuilder

Wrap appended text in builderAction in spans.

Note: the spans will only have the correct position if the builderAction only appends or replaces text. Inserting, deleting, or clearing the text will cause the span to be placed at an incorrect position.

isDigitsOnly

inline fun CharSequence.isDigitsOnly(): Boolean

Returns whether the given CharSequence contains only digits.

See also
isDigitsOnly

italic

inline fun SpannableStringBuilder.italic(builderAction: SpannableStringBuilder.() -> Unit): SpannableStringBuilder

Wrap appended text in builderAction in an italic StyleSpan.

See also
inSpans

parseAsHtml

inline fun String.parseAsHtml(
    flags: Int = FROM_HTML_MODE_LEGACY,
    imageGetter: Html.ImageGetter? = null,
    tagHandler: Html.TagHandler? = null
): Spanned

Returns a Spanned from parsing this string as HTML.

Parameters
flags: Int = FROM_HTML_MODE_LEGACY

Additional option to set the behavior of the HTML parsing. Default is set to Html.FROM_HTML_MODE_LEGACY which was introduced in API 24.

imageGetter: Html.ImageGetter? = null

Returns displayable styled text from the provided HTML string.

tagHandler: Html.TagHandler? = null

Notified when HTML tags are encountered a tag the parser does not know how to interpret.

See also
fromHtml

scale

inline fun SpannableStringBuilder.scale(
    proportion: Float,
    builderAction: SpannableStringBuilder.() -> Unit
): SpannableStringBuilder

Wrap appended text in builderAction in a RelativeSizeSpan.

See also
inSpans

set

inline operator fun Spannable.set(range: IntRange, span: Any): Unit

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

set

inline operator fun Spannable.set(start: Int, end: Int, span: Any): Unit

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

strikeThrough

inline fun SpannableStringBuilder.strikeThrough(builderAction: SpannableStringBuilder.() -> Unit): SpannableStringBuilder

Wrap appended text in builderAction in a StrikethroughSpan.

See also
inSpans

subscript

inline fun SpannableStringBuilder.subscript(builderAction: SpannableStringBuilder.() -> Unit): SpannableStringBuilder

Wrap appended text in builderAction in a SubscriptSpan.

See also
inSpans

superscript

inline fun SpannableStringBuilder.superscript(builderAction: SpannableStringBuilder.() -> Unit): SpannableStringBuilder

Wrap appended text in builderAction in a SuperscriptSpan.

See also
inSpans

toHtml

inline fun Spanned.toHtml(option: Int = TO_HTML_PARAGRAPH_LINES_CONSECUTIVE): String

Returns a string of HTML from the spans in this Spanned.

See also
toHtml

toSpannable

inline fun CharSequence.toSpannable(): Spannable

Returns a new Spannable from CharSequence, or the source itself if it is already an instance of SpannableString.

toSpanned

inline fun CharSequence.toSpanned(): Spanned

Returns a new Spanned from CharSequence, or the source itself if it is already an instance of SpannedString.

trimmedLength

inline fun CharSequence.trimmedLength(): Int

Returns the length that the specified CharSequence would have if spaces and ASCII control characters were trimmed from the start and end, as by String.trim.

See also
getTrimmedLength

underline

inline fun SpannableStringBuilder.underline(builderAction: SpannableStringBuilder.() -> Unit): SpannableStringBuilder

Wrap appended text in builderAction in an UnderlineSpan.

See also
inSpans

Extension properties

layoutDirection

val Locale.layoutDirectionInt

Returns layout direction for a given locale.