如何在 Android Jetpack Compose 中创建项目符号文本列表?
How to create bulleted text list in Android Jetpack compose?
我想要这样的东西:
- 嘿,这是第一段。
- 嘿,这是我的第二段。
这是第二行。
- 嘿,这是第 3 段。
不知道能不能达到预期,请试试
@Preview(showBackground = true)
@Composable
fun TestList() {
val list = listOf(
"Hey This is first paragraph",
"Hey this is my second paragraph. Any this is 2nd line.",
"Hey this is 3rd paragraph."
)
LazyColumn {
items(list) {
Row(Modifier.padding(8.dp),verticalAlignment = Alignment.CenterVertically) {
Canvas(modifier = Modifier.padding(start = 8.dp,end = 8.dp).size(6.dp)){
drawCircle(Color.Black)
}
Text(text = it,fontSize = 12.sp)
}
}
}
}
头脑风暴时找到的。
只是另一种带有注释字符串和只有一个文本的方法。
val bullet = "\u2022"
val messages = listOf(
"Hey This is first paragraph",
"Hey this is my second paragraph. Any this is 2nd line.",
"Hey this is 3rd paragraph."
)
val paragraphStyle = ParagraphStyle(textIndent = TextIndent(restLine = 12.sp))
Text(
buildAnnotatedString {
messages.forEach {
withStyle(style = paragraphStyle) {
append(bullet)
append("\t\t")
append(it)
}
}
}
)
更新:输出截图
我想要这样的东西:
- 嘿,这是第一段。
- 嘿,这是我的第二段。 这是第二行。
- 嘿,这是第 3 段。
不知道能不能达到预期,请试试
@Preview(showBackground = true)
@Composable
fun TestList() {
val list = listOf(
"Hey This is first paragraph",
"Hey this is my second paragraph. Any this is 2nd line.",
"Hey this is 3rd paragraph."
)
LazyColumn {
items(list) {
Row(Modifier.padding(8.dp),verticalAlignment = Alignment.CenterVertically) {
Canvas(modifier = Modifier.padding(start = 8.dp,end = 8.dp).size(6.dp)){
drawCircle(Color.Black)
}
Text(text = it,fontSize = 12.sp)
}
}
}
}
头脑风暴时找到的。 只是另一种带有注释字符串和只有一个文本的方法。
val bullet = "\u2022"
val messages = listOf(
"Hey This is first paragraph",
"Hey this is my second paragraph. Any this is 2nd line.",
"Hey this is 3rd paragraph."
)
val paragraphStyle = ParagraphStyle(textIndent = TextIndent(restLine = 12.sp))
Text(
buildAnnotatedString {
messages.forEach {
withStyle(style = paragraphStyle) {
append(bullet)
append("\t\t")
append(it)
}
}
}
)
更新:输出截图