Save the date! Android Dev Summit is coming to Mountain View, CA on November 7-8, 2018.

androidx.core.text

Classes

BidiFormatter

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

HtmlCompat

Backwards compatible version of Html.

ICUCompat

PrecomputedTextCompat

A text which has the character metrics data.

TextDirectionHeuristicsCompat

Some objects that implement TextDirectionHeuristic.

TextUtilsCompat

Backwards compatible version of TextUtils.

Top-level functions summary

SpannedString

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

Extension functions summary

For kotlin.CharSequence
Boolean

Returns whether the given CharSequence contains only digits.

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.

Spannable

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

Spanned

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

For kotlin.String
Spanned
String.parseAsHtml(flags: Int = FROM_HTML_MODE_LEGACY, imageGetter: ImageGetter? = null, tagHandler: TagHandler? = null)

Returns a Spanned from parsing this string as HTML.

String

Html-encode the string.

For android.text.Spanned
String
Spanned.toHtml(option: Int = TO_HTML_PARAGRAPH_LINES_CONSECUTIVE)

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

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

Get all spans that are instance of T.

For android.text.Spannable
operator Unit

Adds span to the entire text.

operator Unit

Removes span from this text.

Unit

Clear all spans from this text.

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

Add span to the range start&hellip;end of the text.

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

Add span to the range of the text.

For android.text.SpannableStringBuilder
SpannableStringBuilder
SpannableStringBuilder.inSpans(vararg spans: Any, builderAction: SpannableStringBuilder.() -> Unit)

Wrap appended text in builderAction in spans.

SpannableStringBuilder

Wrap appended text in builderAction in span.

SpannableStringBuilder

Wrap appended text in builderAction in a bold StyleSpan.

SpannableStringBuilder

Wrap appended text in builderAction in an italic StyleSpan.

SpannableStringBuilder

Wrap appended text in builderAction in an UnderlineSpan.

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

Wrap appended text in builderAction in a ForegroundColorSpan.

SpannableStringBuilder

Wrap appended text in builderAction in a BackgroundColorSpan.

SpannableStringBuilder

Wrap appended text in builderAction in a StrikethroughSpan.

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

Wrap appended text in builderAction in a RelativeSizeSpan.

SpannableStringBuilder

Wrap appended text in builderAction in a SuperscriptSpan.

SpannableStringBuilder

Wrap appended text in builderAction in a SubscriptSpan.

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: Int, builderAction: SpannableStringBuilder.() -> Unit): SpannableStringBuilder

Wrap appended text in builderAction in a BackgroundColorSpan.

bold

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

Wrap appended text in builderAction in a bold StyleSpan.

clearSpans

inline fun Spannable.clearSpans(): Unit

Clear all spans from this text.

color

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

Wrap appended text in builderAction in a ForegroundColorSpan.

getSpans

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

Get all spans that are instance of T.

htmlEncode

inline fun String.htmlEncode(): String

Html-encode the string.

inSpans

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.

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.

isDigitsOnly

inline fun CharSequence.isDigitsOnly(): Boolean

Returns whether the given CharSequence contains only digits.

italic

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

Wrap appended text in builderAction in an italic StyleSpan.

minusAssign

inline operator fun Spannable.minusAssign(span: Any): Unit

Removes span from this text.

parseAsHtml

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

Returns a Spanned from parsing this string as HTML.

Parameters
flags 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 Returns displayable styled text from the provided HTML string.
tagHandler Notified when HTML tags are encountered a tag the parser does not know how to interpret.

See Also

plusAssign

inline operator fun Spannable.plusAssign(span: Any): Unit

Adds span to the entire text.

scale

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

Wrap appended text in builderAction in a RelativeSizeSpan.

set

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

Add span to the range start&hellip;end of the text.


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

Note: The end value is exclusive.

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.

strikeThrough

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

Wrap appended text in builderAction in a StrikethroughSpan.

subscript

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

Wrap appended text in builderAction in a SubscriptSpan.

superscript

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

Wrap appended text in builderAction in a SuperscriptSpan.

toHtml

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

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

See Also

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.

underline

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

Wrap appended text in builderAction in an UnderlineSpan.