Android 12 Developer Preview is here! Try it out, and give us your feedback!

AnnotatedString

@Immutable class AnnotatedString : CharSequence
kotlin.Any
   ↳ androidx.compose.ui.text.AnnotatedString

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

Summary

Nested classes

Builder class for AnnotatedString.

data

The information attached on the text such as a SpanStyle.

Public constructors
<init>(text: String, spanStyles: List<AnnotatedString.Range<SpanStyle>> = listOf(), paragraphStyles: List<AnnotatedString.Range<ParagraphStyle>> = listOf())

The basic data structure of text with multiple styles.

Public methods
Boolean
equals(other: Any?)

operator Char
get(index: Int)

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

Query the string annotations attached on this AnnotatedString.

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

Query all of the string annotations attached on this AnnotatedString.

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

Query all of the string annotations attached on this AnnotatedString.

Int

operator AnnotatedString

AnnotatedString
subSequence(startIndex: Int, endIndex: Int)

Return a substring for the AnnotatedString and include the styles in the range of startIndex (inclusive) and endIndex (exclusive).

AnnotatedString

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

String

Extension functions
From androidx.compose.ui.text
AnnotatedString
AnnotatedString.capitalize(localeList: LocaleList = LocaleList.current)

Create capitalized AnnotatedString

AnnotatedString
AnnotatedString.decapitalize(localeList: LocaleList = LocaleList.current)

Create capitalized AnnotatedString

AnnotatedString
AnnotatedString.toLowerCase(localeList: LocaleList = LocaleList.current)

Create lower case transformed AnnotatedString

AnnotatedString
AnnotatedString.toUpperCase(localeList: LocaleList = LocaleList.current)

Create upper case transformed AnnotatedString

Inherited extension functions
From androidx.core.text.kotlin.CharSequence
Boolean

Returns whether the given CharSequence contains only digits.

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.

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.

From androidx.compose.ui.text.kotlin.CharSequence
String