androidx.compose.material3

ListItem

Composable function

A list item is one row in a list. It has a headline, and optionally a line above, a line below, something at the start, and something at the end.

Put list items in a LazyColumn for long lists.

One, two and three lines
One, two and three lines
Column(Modifier.width(360.dp)) {
    ListItem(headlineContent = { Text("One line") })
    HorizontalDivider()
    ListItem(
        headlineContent = { Text("Two lines") },
        supportingContent = { Text("Supporting text") },
    )
    HorizontalDivider()
    ListItem(
        overlineContent = { Text("OVERLINE") },
        headlineContent = { Text("Three lines") },
        supportingContent = { Text("Supporting text that is a bit longer") },
    )
}
Leading icon and trailing control
Leading icon and trailing control
var on by remember { mutableStateOf(true) }
ListItem(
    headlineContent = { Text("Notifications") },
    supportingContent = { Text("Sounds and banners") },
    leadingContent = { Icon(Icons.Filled.Notifications, contentDescription = null) },
    trailingContent = { Switch(checked = on, onCheckedChange = { on = it }) },
    modifier = Modifier.width(360.dp),
)

The newer forms (clickable, selectable, toggleable) make the whole row react, and change shape while pressed. They are Expressive.

A whole row that togglesExpressive theme
A whole row that toggles
var checked by remember { mutableStateOf(true) }
ListItem(
    checked = checked,
    onCheckedChange = { checked = it },
    leadingContent = { Checkbox(checked = checked, onCheckedChange = null) },
    supportingContent = { Text("The whole row is clickable") },
    modifier = Modifier.width(360.dp),
) {
    Text("Show previews")
}

SegmentedListItem is for lists where items touch, like a settings group. Give each item the shape for its position, so only the outer corners of the group are round.

Basic

Not clickable. Add Modifier.clickable yourself if needed.

@Composable
fun ListItem(
    headlineContent: @Composable () -> Unit,
    modifier: Modifier = Modifier,
    overlineContent: @Composable (() -> Unit)? = null,
    supportingContent: @Composable (() -> Unit)? = null,
    leadingContent: @Composable (() -> Unit)? = null,
    trailingContent: @Composable (() -> Unit)? = null,
    colors: ListItemColors = ListItemDefaults.colors(),
    tonalElevation: Dp = ListItemDefaults.Elevation,
    shadowElevation: Dp = ListItemDefaults.Elevation,
)

headlineContent: @Composable () -> UnitRequired

The main text of the row. Usually one Text.

modifier: ModifierOptional

Default: Modifier

Changes size, padding, or position. See the Modifier guide.

overlineContent: @Composable (() -> Unit)?Optional

Default: null

A small line above the headline.

supportingContent: @Composable (() -> Unit)?Optional

Default: null

A line or two below the headline, with more detail.

leadingContent: @Composable (() -> Unit)?Optional

Default: null

Something at the start: an icon, an avatar or a checkbox.

An avatar and a trailing text
An avatar and a trailing text
ListItem(
    headlineContent = { Text("Alex Doe") },
    supportingContent = { Text("See you at 6?") },
    leadingContent = {
        Surface(shape = CircleShape, color = MaterialTheme.colorScheme.primaryContainer) {
            Icon(Icons.Filled.Person, contentDescription = null, Modifier.padding(8.dp))
        }
    },
    trailingContent = { Text("12:30") },
    modifier = Modifier.width(360.dp),
)

trailingContent: @Composable (() -> Unit)?Optional

Default: null

Something at the end: a switch, a checkbox, a time or an icon.

colors: ListItemColorsOptional

Default: ListItemDefaults.colors()

Sets background and content colors. Make one with ListItemDefaults.colors.

A highlighted item
A highlighted item
ListItem(
    headlineContent = { Text("Selected") },
    leadingContent = { Icon(Icons.Filled.Favorite, contentDescription = null) },
    colors = androidx.compose.material3.ListItemDefaults.colors(
        containerColor = MaterialTheme.colorScheme.secondaryContainer,
    ),
    modifier = Modifier.width(360.dp),
)

tonalElevation: DpOptional

Default: ListItemDefaults.Elevation

Tints the background a little toward the primary color.

shadowElevation: DpOptional

Default: ListItemDefaults.Elevation

The size of the shadow under the row.

ClickableSince 1.11Experimental

Takes onClick. The headline goes in content.

@Composable
fun ListItem(
    onClick: () -> Unit,
    modifier: Modifier = Modifier,
    enabled: Boolean = true,
    leadingContent: @Composable (() -> Unit)? = null,
    trailingContent: @Composable (() -> Unit)? = null,
    overlineContent: @Composable (() -> Unit)? = null,
    supportingContent: @Composable (() -> Unit)? = null,
    verticalAlignment: Alignment.Vertical = ListItemDefaults.verticalAlignment(),
    onLongClick: (() -> Unit)? = null,
    onLongClickLabel: String? = null,
    shapes: ListItemShapes = ListItemDefaults.shapes(),
    colors: ListItemColors = ListItemDefaults.colors(),
    elevation: ListItemElevation = ListItemDefaults.elevation(),
    contentPadding: PaddingValues = ListItemDefaults.ContentPadding,
    interactionSource: MutableInteractionSource? = null,
    content: @Composable () -> Unit,
)

onClick: () -> UnitRequired

Called when the row is clicked.

enabled: BooleanOptional

Default: true

Set to false to make the row gray and not clickable.

verticalAlignment: Alignment.VerticalOptional

Default: ListItemDefaults.verticalAlignment()

How the leading and trailing content line up with the text: top or centered.

onLongClick: (() -> Unit)?Optional

Default: null

Called when the row is pressed for a long time.

onLongClickLabel: String?Optional

Default: null

What a long press does, for screen readers.

shapes: ListItemShapesOptional

Default: ListItemDefaults.shapes()

Sets the row shape at rest, pressed, selected and so on.

elevation: ListItemElevationOptional

Default: ListItemDefaults.elevation()

Sets the tint and shadow in different states.

contentPadding: PaddingValuesOptional

Default: ListItemDefaults.ContentPadding

Space between the edge of the row and its content.

interactionSource: MutableInteractionSource?Optional

Default: null

Lets you observe or control press, hover and focus states. Leave it null unless your code must react to them. See InteractionSource.

content: @Composable () -> UnitRequired

The main text of the row, in the newer forms. Same as headlineContent.

Same as above: modifier, leadingContent, trailingContent, overlineContent, supportingContent, colors.

SelectableSince 1.11Experimental

Takes selected and onClick.

@Composable
fun ListItem(
    selected: Boolean,
    onClick: () -> Unit,
    modifier: Modifier = Modifier,
    enabled: Boolean = true,
    leadingContent: @Composable (() -> Unit)? = null,
    trailingContent: @Composable (() -> Unit)? = null,
    overlineContent: @Composable (() -> Unit)? = null,
    supportingContent: @Composable (() -> Unit)? = null,
    verticalAlignment: Alignment.Vertical = ListItemDefaults.verticalAlignment(),
    onLongClick: (() -> Unit)? = null,
    onLongClickLabel: String? = null,
    shapes: ListItemShapes = ListItemDefaults.shapes(),
    colors: ListItemColors = ListItemDefaults.colors(),
    elevation: ListItemElevation = ListItemDefaults.elevation(),
    contentPadding: PaddingValues = ListItemDefaults.ContentPadding,
    interactionSource: MutableInteractionSource? = null,
    content: @Composable () -> Unit,
)

selected: BooleanRequired

Whether the row is selected.

Same as above: onClick, modifier, enabled, leadingContent, trailingContent, overlineContent, supportingContent, verticalAlignment, onLongClick, onLongClickLabel, shapes, colors, elevation, contentPadding, interactionSource, content.

ToggleableSince 1.11Experimental

Takes checked and onCheckedChange. The whole row toggles.

@Composable
fun ListItem(
    checked: Boolean,
    onCheckedChange: (Boolean) -> Unit,
    modifier: Modifier = Modifier,
    enabled: Boolean = true,
    leadingContent: @Composable (() -> Unit)? = null,
    trailingContent: @Composable (() -> Unit)? = null,
    overlineContent: @Composable (() -> Unit)? = null,
    supportingContent: @Composable (() -> Unit)? = null,
    verticalAlignment: Alignment.Vertical = ListItemDefaults.verticalAlignment(),
    onLongClick: (() -> Unit)? = null,
    onLongClickLabel: String? = null,
    shapes: ListItemShapes = ListItemDefaults.shapes(),
    colors: ListItemColors = ListItemDefaults.colors(),
    elevation: ListItemElevation = ListItemDefaults.elevation(),
    contentPadding: PaddingValues = ListItemDefaults.ContentPadding,
    interactionSource: MutableInteractionSource? = null,
    content: @Composable () -> Unit,
)

checked: BooleanRequired

Whether the row is checked.

onCheckedChange: (Boolean) -> UnitRequired

Called with the new value when the row is clicked.

Same as above: modifier, enabled, leadingContent, trailingContent, overlineContent, supportingContent, verticalAlignment, onLongClick, onLongClickLabel, shapes, colors, elevation, contentPadding, interactionSource, content.

Longer Example

A contact list: avatar, name and email, a favorite toggle, and dividers that start after the avatar.

The list is a mutableStateListOf. Changing an element (contacts[i] = contact.copy(...)) updates the screen. A whole row is clickable with Modifier.clickable; the star is its own button inside it.

A contact list: avatar, two lines, a favorite toggle, dividers
A contact list: avatar, two lines, a favorite toggle, dividers
val sampleContacts = listOf(

// A list of rows the user can change. mutableStateListOf updates the screen on every change.
val contacts = remember { sampleContacts.take(4).toMutableStateList() }
LazyColumn(Modifier.width(360.dp)) {
    items(contacts, key = { it.id }) { contact ->
        ListItem(
            headlineContent = { Text(contact.name) },
            supportingContent = { Text(contact.email) },
            leadingContent = { Avatar(contact.name) },
            trailingContent = {
                IconToggleButton(
                    checked = contact.favorite,
                    onCheckedChange = { on ->
                        val i = contacts.indexOfFirst { it.id == contact.id }
                        contacts[i] = contact.copy(favorite = on)
                    },
                ) {
                    Icon(
                        Icons.Filled.Star,
                        contentDescription = "Favorite",
                        tint = if (contact.favorite) MaterialTheme.colorScheme.primary
                        else MaterialTheme.colorScheme.outlineVariant,
                    )
                }
            },
            modifier = Modifier.clickable { /* open the contact */ },
        )
        HorizontalDivider(Modifier.padding(start = 72.dp))
    }
}

/** The data of one row. A data class with a stable id, used as the list key. */
data class Contact(val id: Int, val name: String, val email: String, val favorite: Boolean = false)

private val sampleContacts = listOf(
    Contact(1, "Ada Lovelace", "[email protected]", favorite = true),
    Contact(2, "Alan Turing", "[email protected]"),
    Contact(3, "Barbara Liskov", "[email protected]"),
    Contact(4, "Grace Hopper", "[email protected]", favorite = true),
    Contact(5, "Katherine Johnson", "[email protected]"),
    Contact(6, "Linus Torvalds", "[email protected]"),
)

/** A round avatar with the first letter of the name. */
@Composable
private fun Avatar(name: String) {
    Box(
        Modifier.size(40.dp).background(MaterialTheme.colorScheme.primaryContainer, CircleShape),
        contentAlignment = Alignment.Center,
    ) { Text(name.take(1), color = MaterialTheme.colorScheme.onPrimaryContainer) }
}

List item types

See also