AlertDialog
Dialogs provide important prompts in a user flow. They can require an action, communicate information, or help users accomplish a task.
The dialog will position its buttons, typically TextButtons, based on the available space. By default it will try to place them horizontally next to each other and fallback to horizontal placement if not enough space is available.
Simple usage:
Parameters
called when the user tries to dismiss the Dialog by clicking outside or pressing the back button. This is not called when the dismiss button is clicked.
button which is meant to confirm a proposed action, thus resolving what triggered the dialog. The dialog does not set up any events for this button so they need to be set up by the caller.
the Modifier to be applied to this dialog
button which is meant to dismiss the dialog. The dialog does not set up any events for this button so they need to be set up by the caller.
title which should specify the purpose of the dialog. The title is not mandatory, because there may be sufficient information inside the text.
text which presents the details regarding the dialog's purpose.
defines the shape of this dialog's container
the color used for the background of this dialog. Use Color.Transparent to have no color.
the content color used for the icon.
the content color used for the title.
the content color used for the text.
when containerColor is ColorScheme.surface, a translucent primary color overlay is applied on top of the container. A higher tonal elevation value will result in a darker color in light theme and lighter color in dark theme. See also: Surface.
typically platform specific properties to further configure the dialog.
See also
Samples
androidx.compose.material3.samples.AlertDialogSampleandroidx.compose.material3.samples.AlertDialogWithIconSampleDeprecated
Use BasicAlertDialog instead
Replace with
BasicAlertDialog(onDismissRequest, modifier, properties, content)
Dialogs provide important prompts in a user flow. They can require an action, communicate information, or help users accomplish a task.
This basic alert dialog expects an arbitrary content that is defined by the caller. Note that your content will need to define its own styling.
By default, the displayed dialog has the minimum height and width that the Material Design spec defines. If required, these constraints can be overwritten by providing a width
or height
Modifiers.
Basic alert dialog usage with custom content:
Parameters
called when the user tries to dismiss the Dialog by clicking outside or pressing the back button. This is not called when the dismiss button is clicked.
the Modifier to be applied to this dialog's content.
typically platform specific properties to further configure the dialog.
the content of the dialog