Search code examples
androidandroid-compose-textfield

How to create bulleted text list in Android Jetpack Compose?


I want something like this:

• Hey this is my first paragraph.
• Hey this is my second paragraph.
  And this is the second line.
• Hey this is my third paragraph.

Solution

  • Found it while brainstorming. Just another approach with annotated string and only one Text.

    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)
                    }
                }
            }
        )
    

    update: screenshot of output enter image description here