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))
}