compose 设置text 大小颜色

154 阅读1分钟

Jetpack Compost 1.0.0 终于发布了, 代码片记录开始

设置文本不同大小颜色等样式

Text(
    buildAnnotatedString {
        withStyle(style = SpanStyle(color = Color.Blue, fontSize = 22.sp)) {
            append("H")
        }
        withStyle(style = SpanStyle(fontSize = 12.sp)) {
            append("ello ")
        }
        withStyle(
            style = SpanStyle(
                fontSize = 32.sp,
                fontWeight = FontWeight.Bold,
                color = Color.Red
            )
        ) {
            append("W")
        }
        append("orld")
    }
)