stringResource()
函数获取定义的字符串资源,如下所示:Text(text = stringResource(id = R.string.styled_text))
AnnotatedString
类,例如:Text(text = buildAnnotatedString { withStyle(style = SpanStyle(fontWeight = FontWeight.Bold)) { append("bold text") } append(" and ") withStyle(style = SpanStyle(fontStyle = FontStyle.Italic)) { append("italic text") } })
在上面的代码中,buildAnnotatedString
函数创建一个带样式的字符串,可以使用 withStyle
函数来设置文本的样式。最终,使用 Text
组件显示带样式的文本。