Class

BackgroundAnnotation.SpreadValues

Per-edge Dp spread applied to a text range's bounding boxes during the draw phase.

BackgroundAnnotationSpreadSample

@Sampled
@Composable
fun BackgroundAnnotationSpreadSample() {
    val text = remember {
        buildAnnotatedString {
            append("Use positive horizontal and negative vertical ")
            withDrawAnnotation(
                BackgroundAnnotation(
                    color = Color.Cyan.copy(alpha = 0.25f),
                    cornerRadius = 6.dp,
                    // Positive horizontal spread adds side space around the glyphs;
                    // negative vertical spread shrinks from the line top/bottom so wrapped pills
                    // on consecutive lines stay visually separated instead of touching.
                    spread = SpreadValues(horizontal = 4.dp, vertical = (-2).dp),
                    mergeLines = false,
                    border = BackgroundAnnotation.Border(width = 1.dp, color = Color.Blue),
                )
            ) {
                append("SpreadValues on multi-line per-line pills")
            }
            append(" so adjacent lines do not touch.")
        }
    }
    BasicText(text = text, style = TextStyle(fontSize = 16.sp, lineHeight = 24.sp))
}
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: