State of Compose 2023 results are in! Click here to learn more

← Back to Wear Material

AlertDialog

Component
in
Wear Material
. Since 1.0.0-alpha12

Overview

Code Examples

Video

AlertDialog is an opinionated, full screen dialog. This overload offers 5 slots for title, negative button, positive button, optional icon and optional content. The buttons are shown side-by-side below the icon, text and content. AlertDialog is scrollable by default if the content is taller than the viewport.

Example of an AlertDialog with an icon, title, body text and buttons:

Overloads

AlertDialog

@Composable
public fun AlertDialog(
    title: @Composable () -> Unit,
    negativeButton: @Composable () -> Unit,
    positiveButton: @Composable () -> Unit,
    modifier: Modifier = Modifier,
    icon: @Composable (() -> Unit)? = null,
    scrollState: ScrollState = rememberScrollState(),
    backgroundColor: Color = MaterialTheme.colors.background,
    contentColor: Color = contentColorFor(backgroundColor),
    titleColor: Color = contentColor,
    iconTintColor: Color = contentColor,
    contentPadding: PaddingValues = DialogDefaults.ButtonsContentPadding,
    content: @Composable (() -> Unit)? = null
)

Parameters

NameDescription
titleA slot for displaying the title of the dialog, expected to be one or two lines of text.
negativeButtonA slot for a Button indicating negative sentiment (e.g. No). Clicking the button must remove the dialog from the composition hierarchy.
positiveButtonA slot for a Button indicating positive sentiment (e.g. Yes). Clicking the button must remove the dialog from the composition hierarchy.
modifierModifier to be applied to the dialog.
iconOptional slot for an icon to be shown at the top of the dialog.
scrollStateThe scroll state for the dialog so that the scroll position can be displayed e.g. by the PositionIndicator passed to Scaffold.
backgroundColorColor representing the background color for the dialog.
contentColorColor representing the color for content.
titleColorColor representing the color for title.
iconTintColorIcon Color that defaults to contentColor, unless specifically overridden.
contentPaddingThe padding to apply around the whole of the dialog's contents.
contentA slot for additional content, expected to be 2-3 lines of text

AlertDialog

@Composable
public fun AlertDialog(
    title: @Composable () -> Unit,
    modifier: Modifier = Modifier,
    icon: @Composable (() -> Unit)? = null,
    message: @Composable (() -> Unit)? = null,
    scrollState: ScrollState = rememberScrollState(),
    backgroundColor: Color = MaterialTheme.colors.background,
    contentColor: Color = contentColorFor(backgroundColor),
    titleColor: Color = contentColor,
    messageColor: Color = contentColor,
    iconTintColor: Color = contentColor,
    contentPadding: PaddingValues = DialogDefaults.ChipsContentPadding,
    content: @Composable ColumnScope.() -> Unit
)

Parameters

NameDescription
titleA slot for displaying the title of the dialog, expected to be one or two lines of text.
modifierModifier to be applied to the dialog.
iconOptional slot for an icon to be shown at the top of the dialog.
messageOptional slot for additional message content, expected to be 2-3 lines of text.
scrollStateThe scroll state for the dialog so that the scroll position can be displayed e.g. by the PositionIndicator passed to Scaffold.
backgroundColorColor representing the background color for the dialog.
contentColorColor representing the color for content.
titleColorColor representing the color for title.
messageColorColor representing the color for message.
iconTintColorIcon Color that defaults to contentColor, unless specifically overridden.
contentPaddingThe padding to apply around the whole of the dialog's contents.
contentA slot for one or more spaced Chips, stacked vertically