Slide 6
Slide 6 text
その2: テキストの⼀部を装飾
テキストの⼀部を装飾したい場合、AnnotatedStringクラスを使います.
従来のFrameworkではSpannedに相当
@Composable
fun StyledGreeting2(name: String) {
val greetingText = annotatedString {
pushStyle(SpanStyle(color = Color.Green))
append("Hello ")
//
前にpush
したstyle
は引き継がれる
pushStyle(SpanStyle(
fontSize = 40.sp,
// Snip fontFamily, fontStyle, fontWeight
fontSynthesis = FontSynthesis.All,
textDecoration = TextDecoration.Underline
))
append("$name!")
pop() //
直近でpush
したstyle
はpop
できる
}
Text(text = greetingText, fontSize = 30.sp)
}
6