Builder class for AnnotatedString.
AnnotatedStringBuilderAppendableSample
fun AnnotatedStringBuilderAppendableSample() {
val words = listOf("Hello", "World")
buildAnnotatedString {
// joinTo is a Kotlin stdlib function that takes an Appendable
words.joinTo(this, separator = " ", postfix = "!")
toAnnotatedString()
}
}
AnnotatedStringBuilderSample
fun AnnotatedStringBuilderSample() {
buildAnnotatedString {
append("Hello")
// push green text style so that any appended text will be green
pushStyle(SpanStyle(color = Color.Green))
// append new text, this text will be rendered as green
append(" World")
// pop the green style
pop()
// append a string without style
append("!")
// then style the last added word as red, exclamation mark will be red
addStyle(SpanStyle(color = Color.Red), "Hello World".length, this.length)
toAnnotatedString()
}
}