@Composable
fun Text(
text: String,
modifier: Modifier = Modifier,
color: Color = Color.Unspecified,
fontSize: TextUnit = TextUnit.Unspecified,
fontStyle: FontStyle? = null,
fontWeight: FontWeight? = null,
fontFamily: FontFamily? = null,
letterSpacing: TextUnit = TextUnit.Unspecified,
textDecoration: TextDecoration? = null,
textAlign: TextAlign? = null,
lineHeight: TextUnit = TextUnit.Unspecified,
overflow: TextOverflow = TextOverflow.Clip,
softWrap: Boolean = true,
maxLines: Int = Int.MAX_VALUE,
onTextLayout: (TextLayoutResult) -> Unit = {},
style: TextStyle = LocalTextStyle.current
)



字体大小、颜色、粗细、斜体样式
@Composable
fun TextTestView() {
val content =
"Hello Compose!"
Column(Modifier.fillMaxSize()) {
Text(
text = content,
fontSize = 20.sp, // 字体大小
color = colorResource(id = R.color.purple_200), // 字体颜色
fontWeight = FontWeight.Bold, // 字体加粗
fontStyle = FontStyle.Italic // 字体斜体
)
}
}
单行 / 多行,超出显示 ...
在属性介绍中讲解了设置单行不允许换行 softWrap、设置最多显示几行 maxLines、内容超出截取显示 overflow,下面使用代码演示。
设置单行不允许换行,文字超出显示 ...

本文介绍了JetpackCompose中Text组件的使用,包括设置字体大小、颜色、粗细、斜体,单行/多行显示,字体文件引用,字间距,行间距,中划线,文字对齐,选择复制,点击监听,以及文本段落样式和多段内容的处理方法。

3184

被折叠的 条评论
为什么被折叠?



