Text(stringResource(id = R.string.hello_world))
字体颜色 ☆
Text(
text = stringResource(id = R.string.hello_world),
color = Color.Blue
)
或者使用 style
使用定义color
📌 下面可以在
TextStyle
中找到相同属性的。会在标题中加入 ☆
Text(
text = value,
style = TextStyle(
color = Color.Blue
)
)
如果是资源中的颜色 可以使用colorResource
color = colorResource(id = R.color.black)
还可以是
Color(0xffff0000)
Color(red = 0f, green = 0f, blue = 1f)
当然我们最习惯用的还是String
的颜色值,不过Compose 好像没有提供这样的方法,不过可以自己定义一下。例如
//拓展函数
fun Color.Companion.parse(colorString: String): Color =
Color(color = android.graphics.Color.parseColor(colorString))
使用就很简单了
color = Color.parse(“#FF0000”),
文字大小 ☆
Text(
text = stringResource(id = R.string.hello_world),
fontSize = 40.sp
)
字体样式 ☆
Normal
默认Italic
斜体
Column {
Text(
text = value,
fontStyle = FontStyle.Normal
)
Text(
text = value,
fontStyle = FontStyle.Italic
)
}
字体加粗 ☆
Text(
text = value,
fontWeight = FontWeight.W800
)
下图中 左右两边等价