Function

withStyle

Pushes style to the AnnotatedString.Builder, executes block and then pops the style.

AnnotatedStringBuilderWithStyleSample

@Sampled
fun AnnotatedStringBuilderWithStyleSample() {
    buildAnnotatedString {
        withStyle(SpanStyle(color = Color.Green)) {
            // green text style will be applied to all text in this block
            append("Hello")
        }
        toAnnotatedString()
    }
}
Jetpack Compose beyond MaterialFree components, screens and templates for apps that don’t look like Google’s. Copy them into your app, or let your coding agent add them.Browse for free

Content updated: