AlertDialog

Composable Component

AlertDialogs provide important prompts in a user flow. They can require an action, communicate information, or help users accomplish a task. The AlertDialog is scrollable by default if the content exceeds the viewport height.

Android
@Composable
public fun AlertDialog(
    visible: Boolean,
    onDismissRequest: () -> Unit,
    confirmButton: @Composable RowScope.() -> Unit,
    title: @Composable () -> Unit,
    modifier: Modifier = Modifier,
    dismissButton: @Composable RowScope.() -> Unit = {
        AlertDialogDefaults.DismissButton(onDismissRequest)
    },
    icon: @Composable (() -> Unit)? = null,
    text: @Composable (() -> Unit)? = null,
    verticalArrangement: Arrangement.Vertical = AlertDialogDefaults.VerticalArrangement,
    contentPadding: PaddingValues =
        if (icon != null) {
            AlertDialogDefaults.confirmDismissWithIconContentPadding()
        } else {
            AlertDialogDefaults.confirmDismissContentPadding()
        },
    properties: DialogProperties = DialogProperties(),
    content: (ScalingLazyListScope.() -> Unit)? = null,
)

Parameters

visibleA boolean indicating whether the dialog should be displayed.
onDismissRequestA lambda function to be called when the dialog is dismissed by swiping right (typically also called by the dismissButton). Implementation of this lambda must remove the dialog from the composition hierarchy e.g. by setting visible to false.
confirmButtonA slot for a Button indicating positive sentiment. Clicking the button must remove the dialog from the composition hierarchy e.g. by setting visible to false. It's recommended to use AlertDialogDefaults.ConfirmButton in this slot with onClick callback.
titleA slot for displaying the title of the dialog. Title should contain a summary of the dialog's purpose or content and should not exceed 3 lines of text. By default, TextOverflow.Ellipsis will be applied when text exceeds 3 lines.
modifierModifier to be applied to the dialog content.
dismissButtonA slot for a Button indicating negative sentiment. Clicking the button must remove the dialog from the composition hierarchy e.g. by setting visible to false. It's recommended to use AlertDialogDefaults.DismissButton in this slot with onClick callback.
iconOptional slot for an icon to be shown at the top of the dialog.
textOptional slot for displaying the message of the dialog below the title. Should contain additional text that presents further details about the dialog's purpose if the title is insufficient.
verticalArrangementThe vertical arrangement of the dialog's children. There is a default padding between icon, title, and text, which will be added to the spacing specified in this verticalArrangement parameter.
contentPaddingThe padding to apply around the entire dialog's contents. It is recommended to use the defaults, which adjust to reduce the top padding when an icon is present.
propertiesAn optional DialogProperties object for configuring the dialog's behavior.
contentA slot for additional content, displayed within a scrollable ScalingLazyColumn.
Android
@Composable
public fun AlertDialog(
    visible: Boolean,
    onDismissRequest: () -> Unit,
    title: @Composable () -> Unit,
    modifier: Modifier = Modifier,
    icon: @Composable (() -> Unit)? = null,
    text: @Composable (() -> Unit)? = null,
    verticalArrangement: Arrangement.Vertical = AlertDialogDefaults.VerticalArrangement,
    contentPadding: PaddingValues =
        if (icon != null) {
            AlertDialogDefaults.contentWithIconPadding()
        } else {
            AlertDialogDefaults.contentPadding()
        },
    properties: DialogProperties = DialogProperties(),
    content: (ScalingLazyListScope.() -> Unit)? = null,
)

Parameters

visibleA boolean indicating whether the dialog should be displayed.
onDismissRequestA lambda function to be called when the dialog is dismissed by swiping to the right or by other dismiss action. Implementation of this lambda must remove the dialog from the composition hierarchy e.g. by setting visible to false.
titleA slot for displaying the title of the dialog. Title should contain a summary of the dialog's purpose or content and should not exceed 3 lines of text. By default, TextOverflow.Ellipsis will be applied when text exceeds 3 lines.
modifierModifier to be applied to the dialog content.
iconOptional slot for an icon to be shown at the top of the dialog.
textOptional slot for displaying the message of the dialog below the title. Should contain additional text that presents further details about the dialog's purpose if the title is insufficient.
verticalArrangementThe vertical arrangement of the dialog's children. There is a default padding between icon, title, and text, which will be added to the spacing specified in this verticalArrangement parameter.
contentPaddingThe padding to apply around the entire dialog's contents. It is recommended to use the defaults, which adjust to reduce the top padding when an icon is present.
propertiesAn optional DialogProperties object for configuring the dialog's behavior.
contentA slot for additional content, displayed within a scrollable ScalingLazyColumn. Any buttons added in this slot that are intended to dismiss the dialog must remove the dialog from the composition hierarchy e.g. by setting visible to false.
Android
@Composable
public fun AlertDialog(
    visible: Boolean,
    onDismissRequest: () -> Unit,
    edgeButton: (@Composable BoxScope.() -> Unit),
    title: @Composable () -> Unit,
    modifier: Modifier = Modifier,
    icon: @Composable (() -> Unit)? = null,
    text: @Composable (() -> Unit)? = null,
    verticalArrangement: Arrangement.Vertical = AlertDialogDefaults.VerticalArrangement,
    contentPadding: PaddingValues =
        if (icon != null) {
            AlertDialogDefaults.contentWithIconPadding()
        } else {
            AlertDialogDefaults.contentPadding()
        },
    properties: DialogProperties = DialogProperties(),
    content: (ScalingLazyListScope.() -> Unit)? = null,
)

Parameters

visibleA boolean indicating whether the dialog should be displayed.
onDismissRequestA lambda function to be called when the dialog is dismissed by swiping to the right or by other dismiss action. Implementation of this lambda must remove the dialog from the composition hierarchy e.g. by setting visible to false.
edgeButtonSlot for an EdgeButton indicating positive sentiment. Clicking the button must remove the dialog from the composition hierarchy e.g. by setting visible to false. It's recommended to use AlertDialogDefaults.EdgeButton in this slot with onClick callback. Note that when using an EdgeButton which is not Medium size, the contentPadding parameters should be specified.
titleA slot for displaying the title of the dialog. Title should contain a summary of the dialog's purpose or content and should not exceed 3 lines of text.By default, TextOverflow.Ellipsis will be applied when text exceeds 3 lines.
modifierModifier to be applied to the dialog content.
iconOptional slot for an icon to be shown at the top of the dialog.
textOptional slot for displaying the message of the dialog below the title. Should contain additional text that presents further details about the dialog's purpose if the title is insufficient.
verticalArrangementThe vertical arrangement of the dialog's children. There is a default padding between icon, title, and text, which will be added to the spacing specified in this verticalArrangement parameter.
contentPaddingThe padding to apply around the entire dialog's contents. Bottom padding will be ignored and default spacing for the EdgeButton will be used. It is recommended to use the defaults, which adjust to reduce the top padding when an icon is present.
propertiesAn optional DialogProperties object for configuring the dialog's behavior.
contentA slot for additional content, displayed within a scrollable ScalingLazyColumn. Any buttons added in this slot that are intended to dismiss the dialog must remove the dialog from the composition hierarchy e.g. by setting visible to false.