androidx.compose.material3
DropdownMenuItem
Composable function
A part of DropdownMenu. See that page for an overview and examples.
Basic
Text, icons and onClick.
@Composable
fun DropdownMenuItem(
text: @Composable () -> Unit,
onClick: () -> Unit,
modifier: Modifier = Modifier,
leadingIcon: @Composable (() -> Unit)? = null,
trailingIcon: @Composable (() -> Unit)? = null,
enabled: Boolean = true,
colors: MenuItemColors = MenuDefaults.itemColors(),
contentPadding: PaddingValues = MenuDefaults.DropdownMenuItemContentPadding,
interactionSource: MutableInteractionSource? = null,
)
text: @Composable () -> UnitRequired
text: @Composable () -> UnitRequiredThe label of the item.
onClick: () -> UnitRequired
onClick: () -> UnitRequiredCalled when the item is clicked. Close the menu here too.
leadingIcon: @Composable (() -> Unit)?Optional
leadingIcon: @Composable (() -> Unit)?OptionalDefault: null
An icon before the label.
trailingIcon: @Composable (() -> Unit)?Optional
trailingIcon: @Composable (() -> Unit)?OptionalDefault: null
An icon or a short text after the label, like a keyboard shortcut.
enabled: BooleanOptional
enabled: BooleanOptionalDefault: true
Set to false to make the item gray and not clickable.
colors: MenuItemColorsOptional
colors: MenuItemColorsOptionalDefault: MenuDefaults.itemColors()
Sets text and icon colors of the item. Make one with MenuDefaults.itemColors.
contentPadding: PaddingValuesOptional
contentPadding: PaddingValuesOptionalDefault: MenuDefaults.DropdownMenuItemContentPadding
Space between the edge of the item and its content.
interactionSource: MutableInteractionSource?Optional
interactionSource: MutableInteractionSource?OptionalDefault: null
Lets you observe or control press, hover and focus states. Leave it null unless your code must react to them. See InteractionSource.
Same as in DropdownMenu: modifier.
With shapeSince 1.12
Expressive. Takes a shape and supportingText.
@Composable
fun DropdownMenuItem(
onClick: () -> Unit,
text: @Composable () -> Unit,
shape: Shape,
modifier: Modifier = Modifier,
leadingIcon: @Composable (() -> Unit)? = null,
trailingIcon: @Composable (() -> Unit)? = null,
enabled: Boolean = true,
colors: MenuItemColors = MenuDefaults.itemColors(),
horizontalArrangement: Arrangement.Horizontal = MenuDefaults.DropdownMenuItemHorizontalArrangement,
contentPadding: PaddingValues = MenuDefaults.DropdownMenuSelectableItemContentPadding,
interactionSource: MutableInteractionSource? = null,
supportingText: @Composable (() -> Unit)? = null,
)
horizontalArrangement: Arrangement.HorizontalOptional
horizontalArrangement: Arrangement.HorizontalOptionalDefault: MenuDefaults.DropdownMenuItemHorizontalArrangement
Space between the icons and the label.
supportingText: @Composable (() -> Unit)?OptionalSince 1.11
supportingText: @Composable (() -> Unit)?OptionalSince 1.11Default: null
A second, smaller line under the label.
Same as above: onClick, text, leadingIcon, trailingIcon, enabled, colors, contentPadding, interactionSource.
Same as in DropdownMenu: shape, modifier.
CheckableSince 1.12
Expressive. Takes checked and onCheckedChange, like a checkbox.
@Composable
fun DropdownMenuItem(
checked: Boolean,
onCheckedChange: (Boolean) -> Unit,
text: @Composable () -> Unit,
shapes: MenuItemShapes,
modifier: Modifier = Modifier,
leadingIcon: @Composable (() -> Unit)? = null,
checkedLeadingIcon: @Composable (() -> Unit)? = null,
trailingIcon: @Composable (() -> Unit)? = null,
supportingText: @Composable (() -> Unit)? = null,
enabled: Boolean = true,
colors: MenuItemColors = MenuDefaults.selectableItemColors(),
horizontalArrangement: Arrangement.Horizontal = MenuDefaults.DropdownMenuItemHorizontalArrangement,
contentPadding: PaddingValues = MenuDefaults.DropdownMenuSelectableItemContentPadding,
interactionSource: MutableInteractionSource? = null,
)
checked: BooleanRequiredSince 1.11
checked: BooleanRequiredSince 1.11Whether a checkable item is checked.
onCheckedChange: (Boolean) -> UnitRequiredSince 1.11
onCheckedChange: (Boolean) -> UnitRequiredSince 1.11Called with the new value when a checkable item is clicked.
shapes: MenuItemShapesRequiredSince 1.11
shapes: MenuItemShapesRequiredSince 1.11Sets the item shapes at rest, checked and pressed.
checkedLeadingIcon: @Composable (() -> Unit)?OptionalSince 1.11
checkedLeadingIcon: @Composable (() -> Unit)?OptionalSince 1.11Default: null
The leading icon while the item is checked, usually a checkmark.
Same as above: text, leadingIcon, trailingIcon, supportingText, enabled, colors, horizontalArrangement, contentPadding, interactionSource.
Same as in DropdownMenu: modifier.
SelectableSince 1.12
Expressive. Takes selected and onClick, like a radio button.
@Composable
fun DropdownMenuItem(
selected: Boolean,
onClick: () -> Unit,
text: @Composable () -> Unit,
shapes: MenuItemShapes,
modifier: Modifier = Modifier,
leadingIcon: @Composable (() -> Unit)? = null,
selectedLeadingIcon: @Composable (() -> Unit)? = null,
trailingIcon: @Composable (() -> Unit)? = null,
supportingText: @Composable (() -> Unit)? = null,
enabled: Boolean = true,
colors: MenuItemColors = MenuDefaults.selectableItemColors(),
horizontalArrangement: Arrangement.Horizontal = MenuDefaults.DropdownMenuItemHorizontalArrangement,
contentPadding: PaddingValues = MenuDefaults.DropdownMenuSelectableItemContentPadding,
interactionSource: MutableInteractionSource? = null,
)
selected: BooleanRequiredSince 1.11
selected: BooleanRequiredSince 1.11Whether a selectable item is selected.
selectedLeadingIcon: @Composable (() -> Unit)?OptionalSince 1.11
selectedLeadingIcon: @Composable (() -> Unit)?OptionalSince 1.11Default: null
The leading icon while the item is selected.
Same as above: onClick, text, shapes, leadingIcon, trailingIcon, supportingText, enabled, colors, horizontalArrangement, contentPadding, interactionSource.
Same as in DropdownMenu: modifier.
Parts
DropdownMenuDropdownMenuItemDropdownMenuGroupDropdownMenuPopup