AnnotatedString 객체를 만드는 inline function 이다.
동일한 Text 컴포저블 내에서 여러 스타일을 설정할 수 있도록 하는 객체이다.
ParagraphStyle 은 전체 단락에 적용할 수 있고 SpanStyle 은 문자 수준에서 적용할 수 있다.
// use SpanStyle
Text(
buildAnnotatedString {
withStyle(
style = SpanStyle(
color = Color.Blue
)
) {
append("H")
}
append("ello ")
withStyle(
style = SpanStyle(
fontWeight = FontWeight.Bold,
color = Color.Red
)
) {
append("W")
}
append("orld")
}
)
// use ParagraphStyle
Text(
buildAnnotatedString {
withStyle(style = ParagraphStyle(lineHeight = 30.sp)) {
withStyle(
style = SpanStyle(
color = Color.Blue
)
) {
append("Hello\n")
}
withStyle(
style = SpanStyle(
fontWeight = FontWeight.Bold,
color = Color.Red
)
) {
append("World\n")
}
append("Compose")
}
}
)
https://developer.android.com/jetpack/compose/text?hl=ko
https://kotlinworld.com/224