androidx.compose.ui.text

AnnotatedString

Class · from org.jetbrains.compose.ui:ui-text:1.12.2

No hand-written docs yet.

The basic data structure of text with multiple styles. To construct an AnnotatedString you can use Builder.

class AnnotatedString : CharSequence

Is a

How to get one

Create it

Ready-made values and functions that return it

Used by

Parameters that take a AnnotatedString.

Properties

spanStyles

val spanStyles: List<Range<SpanStyle>>

All SpanStyle that have been applied to a range of this String

paragraphStyles

val paragraphStyles: List<Range<ParagraphStyle>>

All ParagraphStyle that have been applied to a range of this String

Saver

val Saver: Saver<AnnotatedString, *>

The default Saver implementation for AnnotatedString.

text

val text: String

Functions

subSequence

fun subSequence(range: TextRange): AnnotatedString

Return a substring for the AnnotatedString and include the styles in the given range.

plus

fun plus(other: AnnotatedString): AnnotatedString

getStringAnnotations

fun getStringAnnotations(
    tag: String,
    start: Int,
    end: Int,
): List<Range<String>>

Query the string annotations attached on this AnnotatedString. Annotations are metadata attached on the AnnotatedString, for example, a URL is a string metadata attached on the a certain range. Annotations are also store with Range like the styles.

hasStringAnnotations

fun hasStringAnnotations(
    tag: String,
    start: Int,
    end: Int,
): Boolean

Returns true if getStringAnnotations with the same parameters would return a non-empty list

fun getStringAnnotations(start: Int, end: Int): List<Range<String>>

Query all of the string annotations attached on this AnnotatedString.

getTtsAnnotations

fun getTtsAnnotations(start: Int, end: Int): List<Range<TtsAnnotation>>

Query all of the TtsAnnotations attached on this AnnotatedString.

getLinkAnnotations

fun getLinkAnnotations(start: Int, end: Int): List<Range<LinkAnnotation>>

Query all of the LinkAnnotations attached on this AnnotatedString.

hasLinkAnnotations

fun hasLinkAnnotations(start: Int, end: Int): Boolean

Returns true if getLinkAnnotations with the same parameters would return a non-empty list

hasEqualAnnotations

fun hasEqualAnnotations(other: AnnotatedString): Boolean

Compare the annotations between this and another AnnotatedString.

mapAnnotations

fun mapAnnotations(
    transform: (Range<out Annotation>) -> Range<out Annotation>,
): AnnotatedString

Returns a new AnnotatedString where a list of annotations contains the results of applying the given transform function to each element in the original annotations list.

flatMapAnnotations

fun flatMapAnnotations(
    transform: (Range<out Annotation>) -> List<Range<out Annotation>>,
): AnnotatedString

Returns a new AnnotatedString where a list of annotations contains all elements yielded from results transform function being invoked on each element of original annotations list.

Nested types

Library docs

The basic data structure of text with multiple styles. To construct an AnnotatedString you can use Builder.