androidx.compose.material3

DropdownMenu

Composable function

A menu shows a list of choices on top of the screen, usually opened from a "more" button.

The menu opens next to its parent. Put the button and the DropdownMenu in the same Box. The menu is shown while expanded is true. You keep that in a variable.

A menu opened from a button
A menu opened from a button
var expanded by remember { mutableStateOf(true) }
// The outer Box only gives the picture room for the open menu.
Box(Modifier.size(260.dp, 240.dp), contentAlignment = Alignment.TopEnd) {
    // The menu opens next to its parent: put the button and the menu in one Box.
    Box {
        IconButton(onClick = { expanded = true }) { Icon(Icons.Filled.MoreVert, "More options") }
        DropdownMenu(expanded = expanded, onDismissRequest = { expanded = false }) {
            DropdownMenuItem(text = { Text("Edit") }, onClick = { expanded = false })
            DropdownMenuItem(text = { Text("Share") }, onClick = { expanded = false })
            DropdownMenuItem(text = { Text("Delete") }, onClick = { expanded = false })
        }
    }
}
Icons, a divider and a disabled item
Icons, a divider and a disabled item
Box(Modifier.size(260.dp, 300.dp)) {
    Box {
        IconButton(onClick = {}) { Icon(Icons.Filled.MoreVert, "More options") }
        DropdownMenu(expanded = true, onDismissRequest = {}) {
            DropdownMenuItem(
                text = { Text("Edit") },
                onClick = {},
                leadingIcon = { Icon(Icons.Filled.Edit, null) },
            )
            DropdownMenuItem(
                text = { Text("Share") },
                onClick = {},
                leadingIcon = { Icon(Icons.Filled.Share, null) },
                trailingIcon = { Text("Ctrl+S") },
            )
            HorizontalDivider()
            DropdownMenuItem(
                text = { Text("Delete") },
                onClick = {},
                leadingIcon = { Icon(Icons.Filled.Delete, null) },
                enabled = false,
            )
        }
    }
}

Expressive menus can split items into groups: put DropdownMenuGroups inside a DropdownMenuPopup.

To pick a value in a form, use an ExposedDropdownMenuBox instead.

Parameters

@Composable
fun DropdownMenu(
    expanded: Boolean,
    onDismissRequest: () -> Unit,
    modifier: Modifier = Modifier,
    offset: DpOffset = DpOffset(0.dp, 0.dp),
    scrollState: ScrollState = rememberScrollState(),
    properties: PopupProperties = DefaultMenuProperties,
    shape: Shape = MenuDefaults.shape,
    containerColor: Color = MenuDefaults.containerColor,
    tonalElevation: Dp = MenuDefaults.TonalElevation,
    shadowElevation: Dp = MenuDefaults.ShadowElevation,
    border: BorderStroke? = null,
    content: @Composable ColumnScope.() -> Unit,
)

expanded: BooleanRequired

Whether the menu is open. Pass your state here.

onDismissRequest: () -> UnitRequired

Called when the user taps outside the menu or presses back. Set your state to false here.

modifier: ModifierOptional

Default: Modifier

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

offset: DpOffsetOptional

Default: DpOffset(0.dp, 0.dp)

Moves the menu from its default position.

scrollState: ScrollStateOptional

Default: rememberScrollState()

Controls scrolling when the menu is too long for the screen.

properties: PopupPropertiesOptional

Default: DefaultMenuProperties

Popup options, like whether the menu takes focus.

shape: ShapeOptional

Default: MenuDefaults.shape

Sets the outline of the menu or item. See the Shapes guide.

containerColor: ColorOptional

Default: MenuDefaults.containerColor

The background color of the menu.

tonalElevation: DpOptional

Default: MenuDefaults.TonalElevation

Tints the menu background a little toward the primary color.

shadowElevation: DpOptional

Default: MenuDefaults.ShadowElevation

The size of the shadow under the menu.

border: BorderStroke?Optional

Default: null

Draws an outline around the menu.

content: @Composable ColumnScope.() -> UnitRequired

The items. Add one DropdownMenuItem each. Items are placed in a Column. Add a HorizontalDivider between groups.

Parts