Compose Component

AlertDialog

Displays an urgent prompt requiring the user to acknowledge or take an action.

AlertDialog

Source set: Android
@Composable
public fun AlertDialog(
    onDismissRequest: () -> Unit,
    confirmButton: @Composable () -> Unit,
    modifier: Modifier = Modifier,
    dismissButton: @Composable (() -> Unit)? = null,
    icon: @Composable (() -> Unit)? = null,
    title: @Composable (() -> Unit)? = null,
    text: @Composable (() -> Unit)? = null,
    containerShape: Shape = AlertDialogDefaults.containerShape,
    containerColor: Color = AlertDialogDefaults.containerColor,
    containerContentColor: Color = AlertDialogDefaults.containerContentColor(containerColor),
    containerContentPadding: PaddingValues = AlertDialogDefaults.containerContentPadding,
)

Parameters

onDismissRequest called when the user tries to dismiss the dialog
confirmButton button used to confirm or accept the action. This will be the first button shown and takes focus upon the dialog being opened. This button is placed outside the dialog container, below it, so containerShape, containerColor, containerContentColor, and containerContentPadding do not apply to it
modifier the Modifier to be applied to the outer layout containing the dialog container, confirmButton, and dismissButton
dismissButton optional button used to dismiss or cancel the alert dialog. This button is placed outside the dialog container, next to confirmButton, so containerShape, containerColor, containerContentColor, and containerContentPadding do not apply to it
icon optional icon displayed at the top of the dialog, above the title
title optional title displaying the primary headline of the dialog, placed below the icon and above the text
text optional body text providing additional details or explanation for the dialog, placed below the title
containerShape the Shape of the dialog container
containerColor the background Color of the dialog container
containerContentColor the default Color for the icon, title, and text inside the dialog container
containerContentPadding the spacing values to apply internally between the dialog container and its content

Content updated: