buildAnnotatedString

Function

Common
inline fun buildAnnotatedString(builder: (Builder).() -> Unit): AnnotatedString

Build a new AnnotatedString by populating newly created AnnotatedString.Builder provided by builder.

Parameters

builderlambda to modify AnnotatedString.Builder

Code Examples

AnnotatedStringBuilderLambdaSample

fun AnnotatedStringBuilderLambdaSample() {
    // create an AnnotatedString using the lambda builder
    buildAnnotatedString {
        // append "Hello" with red text color
        withStyle(SpanStyle(color = Color.Red)) { append("Hello") }
        append(" ")
        // append "Hello" with blue text color
        withStyle(SpanStyle(color = Color.Blue)) { append("World!") }
    }
}