Draws a bullet point next to a paragraph.

Bullets do not add indentation. The call site must provide sufficient leading space to accommodate the bullet and its padding, preventing overlap with the text.

There are several ways to achieve this leading space. One common approach is to use ParagraphStyle with textIndent within an AnnotatedString.

import androidx.compose.foundation.text.BasicText
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.graphics.drawscope.Stroke
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.Bullet
import androidx.compose.ui.text.buildAnnotatedString

val bullet1 = Bullet.Default.copy(shape = RectangleShape)
val bullet2 = bullet1.copy(drawStyle = Stroke(2f))
val bullet3 = bullet1.copy(brush = SolidColor(Color.LightGray))
BasicText(
    buildAnnotatedString {
        withBulletList(bullet = bullet1) {
            withBulletListItem { append("Item 1") }
            withBulletList(bullet = bullet2) {
                withBulletListItem { append("Item 2") }
                withBulletListItem { append("Item 3") }
                withBulletList(bullet = bullet3) { withBulletListItem { append("Item 4") } }
            }
            withBulletListItem { append("Item 5") }
        }
    }
)

Summary

Public companion properties

Bullet

Default bullet used in AnnotatedString's bullet list

Cmn
TextUnit

Indentation required to fit Default bullet.

Cmn
TextUnit

Padding between bullet and start of paragraph for Default bullet

Cmn
TextUnit

Height and width for Default bullet.

Cmn

Public constructors

Bullet(
    shape: Shape,
    width: TextUnit,
    height: TextUnit,
    padding: TextUnit,
    brush: Brush?,
    alpha: Float,
    drawStyle: DrawStyle
)
Cmn

Public functions

Bullet
copy(
    shape: Shape,
    width: TextUnit,
    height: TextUnit,
    padding: TextUnit,
    brush: Brush?,
    alpha: Float,
    drawStyle: DrawStyle
)

Copies the existing Bullet replacing some of the fields as desired.

Cmn
open operator Boolean
equals(other: Any?)
Cmn
open Int
Cmn
open String
Cmn

Public properties

Float

opacity to be applied to brush drawing a bullet from 0.0f to 1.0f representing fully transparent to fully opaque respectively.

Cmn
Brush?

brush to draw a bullet with.

Cmn
DrawStyle

defines the draw style of the bullet, e.g. a fill or a stroke

Cmn
TextUnit

the height of the bullet

Cmn
TextUnit

the padding between the end of the bullet and the start of the paragraph

Cmn
Shape

the shape of the bullet to draw

Cmn
TextUnit

the width of the bullet

Cmn

Public companion properties

Default

val DefaultBullet

Default bullet used in AnnotatedString's bullet list

DefaultIndentation

val DefaultIndentationTextUnit

Indentation required to fit Default bullet.

DefaultPadding

val DefaultPaddingTextUnit

Padding between bullet and start of paragraph for Default bullet

DefaultSize

val DefaultSizeTextUnit

Height and width for Default bullet.

Public constructors

Bullet

Bullet(
    shape: Shape,
    width: TextUnit,
    height: TextUnit,
    padding: TextUnit,
    brush: Brush? = null,
    alpha: Float = Float.NaN,
    drawStyle: DrawStyle = Fill
)
Parameters
shape: Shape

the shape of the bullet to draw

width: TextUnit

the width of the bullet

height: TextUnit

the height of the bullet

padding: TextUnit

the padding between the end of the bullet and the start of the paragraph

brush: Brush? = null

brush to draw a bullet with. If null is passed, the bullet will be drawn like the rest of the text

alpha: Float = Float.NaN

opacity to be applied to brush drawing a bullet from 0.0f to 1.0f representing fully transparent to fully opaque respectively. When Float.NaN is passed, the alpha will not be changed and the one used for drawing rest of the text is used

drawStyle: DrawStyle = Fill

defines the draw style of the bullet, e.g. a fill or a stroke

Public functions

copy

fun copy(
    shape: Shape = this.shape,
    width: TextUnit = this.width,
    height: TextUnit = this.height,
    padding: TextUnit = this.padding,
    brush: Brush? = this.brush,
    alpha: Float = this.alpha,
    drawStyle: DrawStyle = this.drawStyle
): Bullet

Copies the existing Bullet replacing some of the fields as desired.

equals

open operator fun equals(other: Any?): Boolean

hashCode

open fun hashCode(): Int

toString

open fun toString(): String

Public properties

alpha

val alphaFloat

opacity to be applied to brush drawing a bullet from 0.0f to 1.0f representing fully transparent to fully opaque respectively. When Float.NaN is passed, the alpha will not be changed and the one used for drawing rest of the text is used

brush

val brushBrush?

brush to draw a bullet with. If null is passed, the bullet will be drawn like the rest of the text

drawStyle

val drawStyleDrawStyle

defines the draw style of the bullet, e.g. a fill or a stroke

height

val heightTextUnit

the height of the bullet

padding

val paddingTextUnit

the padding between the end of the bullet and the start of the paragraph

shape

val shapeShape

the shape of the bullet to draw

width

val widthTextUnit

the width of the bullet