如何在 Android Jetpack Compose 中创建项目符号文本列表?

Cod*_*kas 18 android android-compose-textfield

我想要这样的东西:

\n
\xe2\x80\xa2 Hey this is my first paragraph.\n\xe2\x80\xa2 Hey this is my second paragraph.\n  And this is the second line.\n\xe2\x80\xa2 Hey this is my third paragraph.\n
Run Code Online (Sandbox Code Playgroud)\n

Cod*_*kas 27

头脑风暴的时候发现的。这只是另一种带有注释字符串和只有一个文本的方法。

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)
                }
            }
        }
    )
Run Code Online (Sandbox Code Playgroud)

更新:输出的屏幕截图 在此输入图像描述

  • 不幸的是,它不适用于所有手机(根据屏幕分辨率,12 像素休息线不会与两个选项卡对齐) (5认同)
  • 当然。我已经更新了我的答案。 (2认同)

Ysh*_*shh 7

不知道是否能达到预期,请尝试一下

@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)
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)