AlertDialog

Functions summary

Unit
@Composable
AlertDialog(
    visible: Boolean,
    onDismissRequest: () -> Unit,
    title: @Composable () -> Unit,
    modifier: Modifier,
    icon: (@Composable () -> Unit)?,
    text: (@Composable () -> Unit)?,
    verticalArrangement: Arrangement.Vertical,
    contentPadding: PaddingValues,
    properties: DialogProperties,
    content: (ScalingLazyListScope.() -> Unit)?
)

Dialogs provide important prompts in a user flow.

Unit
@Composable
AlertDialog(
    visible: Boolean,
    onDismissRequest: () -> Unit,
    edgeButton: @Composable BoxScope.() -> Unit,
    title: @Composable () -> Unit,
    modifier: Modifier,
    icon: (@Composable () -> Unit)?,
    text: (@Composable () -> Unit)?,
    verticalArrangement: Arrangement.Vertical,
    contentPadding: PaddingValues,
    properties: DialogProperties,
    content: (ScalingLazyListScope.() -> Unit)?
)

Dialogs provide important prompts in a user flow.

Unit
@Composable
AlertDialog(
    visible: Boolean,
    onDismissRequest: () -> Unit,
    title: @Composable () -> Unit,
    transformationSpec: TransformationSpec,
    modifier: Modifier,
    icon: (@Composable () -> Unit)?,
    text: (@Composable () -> Unit)?,
    verticalArrangement: Arrangement.Vertical,
    contentPadding: @Composable (Boolean) -> PaddingValues,
    properties: DialogProperties,
    content: (TransformingLazyColumnScope.() -> Unit)?
)

Dialogs provide important prompts in a user flow.

Unit
@Composable
AlertDialog(
    visible: Boolean,
    onDismissRequest: () -> Unit,
    confirmButton: @Composable RowScope.() -> Unit,
    title: @Composable () -> Unit,
    modifier: Modifier,
    dismissButton: @Composable RowScope.() -> Unit,
    icon: (@Composable () -> Unit)?,
    text: (@Composable () -> Unit)?,
    verticalArrangement: Arrangement.Vertical,
    contentPadding: PaddingValues,
    properties: DialogProperties,
    content: (ScalingLazyListScope.() -> Unit)?
)

AlertDialogs provide important prompts in a user flow.

Unit
@Composable
AlertDialog(
    visible: Boolean,
    onDismissRequest: () -> Unit,
    edgeButton: @Composable BoxScope.() -> Unit,
    title: @Composable () -> Unit,
    transformationSpec: TransformationSpec,
    modifier: Modifier,
    icon: (@Composable () -> Unit)?,
    text: (@Composable () -> Unit)?,
    verticalArrangement: Arrangement.Vertical,
    contentPadding: PaddingValues,
    properties: DialogProperties,
    content: (TransformingLazyColumnScope.() -> Unit)?
)

Dialogs provide important prompts in a user flow.

Unit
@Composable
AlertDialog(
    visible: Boolean,
    onDismissRequest: () -> Unit,
    confirmButton: @Composable RowScope.() -> Unit,
    title: @Composable () -> Unit,
    transformationSpec: TransformationSpec,
    modifier: Modifier,
    dismissButton: @Composable RowScope.() -> Unit,
    icon: (@Composable () -> Unit)?,
    text: (@Composable () -> Unit)?,
    verticalArrangement: Arrangement.Vertical,
    contentPadding: PaddingValues,
    properties: DialogProperties,
    content: (TransformingLazyColumnScope.() -> Unit)?
)

AlertDialogs provide important prompts in a user flow.

Functions

@Composable
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
): Unit

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

This overload doesn't have any dedicated slots for buttons. It has a content slot so that the caller has flexibility in how to seek user input. In most cases, we recommend using other AlertDialog variations with 2 confirm/dismiss buttons or a single confirmation button.

Where user input is not required, such as displaying a transient success or failure message, use ConfirmationDialog, SuccessConfirmationDialog or FailureConfirmationDialog instead.

AlertDialog now additionally offers an equivalent overload using TransformingLazyColumn, which is recommended to achieve a consistent Material 3 scrolling experience throughout your app

Parameters
visible: Boolean

A boolean indicating whether the dialog should be displayed.

onDismissRequest: () -> Unit

A 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.

title: @Composable () -> Unit

A 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.

modifier: Modifier = Modifier

Modifier to be applied to the dialog content.

icon: (@Composable () -> Unit)? = null

Optional slot for an icon to be shown at the top of the dialog.

text: (@Composable () -> Unit)? = null

Optional 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.

verticalArrangement: Arrangement.Vertical = AlertDialogDefaults.VerticalArrangement

The 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.

contentPadding: PaddingValues = if (icon != null) { AlertDialogDefaults.contentWithIconPadding() } else { AlertDialogDefaults.contentPadding() }

The 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.

properties: DialogProperties = DialogProperties()

An optional DialogProperties object for configuring the dialog's behavior.

content: (ScalingLazyListScope.() -> Unit)? = null

A 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.

@Composable
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
): Unit

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

This overload has a single slot for a confirm EdgeButton at the bottom of the dialog, which should be used when the user will be presented with a single acknowledgement.

Where user input is not required, such as displaying a transient success or failure message, use ConfirmationDialog, SuccessConfirmationDialog or FailureConfirmationDialog instead.

AlertDialog now additionally offers an equivalent overload using TransformingLazyColumn, which is recommended to achieve a consistent Material 3 scrolling experience throughout your app

Example of an AlertDialog with an icon, title, text and bottom EdgeButton:

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.size
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.AccountCircle
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.wear.compose.material3.AlertDialog
import androidx.wear.compose.material3.AlertDialogDefaults
import androidx.wear.compose.material3.Button
import androidx.wear.compose.material3.FilledTonalButton
import androidx.wear.compose.material3.Icon
import androidx.wear.compose.material3.MaterialTheme
import androidx.wear.compose.material3.Text

var showDialog by remember { mutableStateOf(false) }

Box(Modifier.fillMaxSize()) {
    FilledTonalButton(
        modifier = Modifier.align(Alignment.Center),
        onClick = { showDialog = true },
        label = { Text("Show Dialog") },
    )
}

AlertDialog(
    visible = showDialog,
    onDismissRequest = { showDialog = false },
    icon = {
        Icon(
            Icons.Rounded.AccountCircle,
            modifier = Modifier.size(32.dp),
            contentDescription = null,
            tint = MaterialTheme.colorScheme.primary,
        )
    },
    title = { Text("Mobile network is not currently available") },
    text = { Text("Please try again later or check your network settings.") },
    edgeButton = {
        AlertDialogDefaults.EdgeButton(
            onClick = {
                // Perform confirm action here
                showDialog = false
            }
        )
    },
)

Example of an AlertDialog with content groups and a bottom EdgeButton:

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.wear.compose.material3.AlertDialog
import androidx.wear.compose.material3.AlertDialogDefaults
import androidx.wear.compose.material3.Button
import androidx.wear.compose.material3.FilledTonalButton
import androidx.wear.compose.material3.SwitchButton
import androidx.wear.compose.material3.Text

var showDialog by remember { mutableStateOf(false) }
var weatherEnabled by remember { mutableStateOf(false) }
var calendarEnabled by remember { mutableStateOf(false) }

Box(Modifier.fillMaxSize()) {
    FilledTonalButton(
        modifier = Modifier.align(Alignment.Center),
        onClick = { showDialog = true },
        label = { Text("Show Dialog") },
    )
}
AlertDialog(
    visible = showDialog,
    onDismissRequest = { showDialog = false },
    title = { Text("Share your location") },
    text = { Text(" The following apps have asked you to share your location") },
    edgeButton = {
        AlertDialogDefaults.EdgeButton(
            onClick = {
                // Perform confirm action here
                showDialog = false
            }
        ) {
            Text("Share once")
        }
    },
) {
    item {
        SwitchButton(
            modifier = Modifier.fillMaxWidth(),
            checked = weatherEnabled,
            onCheckedChange = { weatherEnabled = it },
            label = { Text("Weather") },
        )
    }
    item {
        SwitchButton(
            modifier = Modifier.fillMaxWidth(),
            checked = calendarEnabled,
            onCheckedChange = { calendarEnabled = it },
            label = { Text("Calendar") },
        )
    }
    item { AlertDialogDefaults.GroupSeparator() }
    item {
        FilledTonalButton(
            modifier = Modifier.fillMaxWidth(),
            onClick = {},
            label = { Text(modifier = Modifier.fillMaxWidth(), text = "Never share") },
        )
    }
    item {
        FilledTonalButton(
            modifier = Modifier.fillMaxWidth(),
            onClick = {},
            label = { Text(modifier = Modifier.fillMaxWidth(), text = "Share always") },
        )
    }
}
Parameters
visible: Boolean

A boolean indicating whether the dialog should be displayed.

onDismissRequest: () -> Unit

A 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.

edgeButton: @Composable BoxScope.() -> Unit

Slot 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.

title: @Composable () -> Unit

A 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.

modifier: Modifier = Modifier

Modifier to be applied to the dialog content.

icon: (@Composable () -> Unit)? = null

Optional slot for an icon to be shown at the top of the dialog.

text: (@Composable () -> Unit)? = null

Optional 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.

verticalArrangement: Arrangement.Vertical = AlertDialogDefaults.VerticalArrangement

The 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.

contentPadding: PaddingValues = if (icon != null) { AlertDialogDefaults.contentWithIconPadding() } else { AlertDialogDefaults.contentPadding() }

The 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.

properties: DialogProperties = DialogProperties()

An optional DialogProperties object for configuring the dialog's behavior.

content: (ScalingLazyListScope.() -> Unit)? = null

A 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.

@Composable
fun AlertDialog(
    visible: Boolean,
    onDismissRequest: () -> Unit,
    title: @Composable () -> Unit,
    transformationSpec: TransformationSpec,
    modifier: Modifier = Modifier,
    icon: (@Composable () -> Unit)? = null,
    text: (@Composable () -> Unit)? = null,
    verticalArrangement: Arrangement.Vertical = AlertDialogDefaults.VerticalArrangement,
    contentPadding: @Composable (Boolean) -> PaddingValues = { isScrollable: Boolean -> if (icon != null) { AlertDialogDefaults.buttonStackWithIconContentPadding(isScrollable) } else { AlertDialogDefaults.buttonStackContentPadding(isScrollable) } },
    properties: DialogProperties = DialogProperties(),
    content: (TransformingLazyColumnScope.() -> Unit)? = null
): Unit

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

This overload doesn't have any dedicated slots for buttons, but it does have a content slot so that the caller has flexibility in how to seek user input. It uses a TransformationSpec for advanced control over transformations of scrolling content.

In most cases, we recommend using other AlertDialog variations with 2 confirm/dismiss buttons or a single confirmation button. Where user input is not required, such as displaying a transient success or failure message, use ConfirmationDialog, SuccessConfirmationDialog or FailureConfirmationDialog instead.

The transformationSpec parameter enables the use of a TransformingLazyColumn internally for advanced control over transformations of scrolling content, which can not be achieved with ScalingLazyColumn.

Parameters
visible: Boolean

A boolean indicating whether the dialog should be displayed.

onDismissRequest: () -> Unit

A 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.

title: @Composable () -> Unit

A 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.

transformationSpec: TransformationSpec

A spec that defines how items inside the TransformingLazyColumn transform and animate as they are scrolled. It is recommended to create a spec using rememberTransformationSpec. This parameter is the key differentiator from the standard AlertDialog overload, which uses a ScalingLazyColumn without per-item customizable animations. The provided transformationSpec is automatically applied only to the dialog's standard components (title, text, and buttons), while additional items in content lambda need to be handled manually, by applying a TransformationSpec to each of them. First item has a fixed spec, with a reduced transition area, so that the top item does not appear scaled or faded when the dialog is initially displayed.

modifier: Modifier = Modifier

Modifier to be applied to the dialog content.

icon: (@Composable () -> Unit)? = null

Optional slot for an icon to be shown at the top of the dialog.

text: (@Composable () -> Unit)? = null

Optional 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.

verticalArrangement: Arrangement.Vertical = AlertDialogDefaults.VerticalArrangement

The 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.

contentPadding: @Composable (Boolean) -> PaddingValues = { isScrollable: Boolean -> if (icon != null) { AlertDialogDefaults.buttonStackWithIconContentPadding(isScrollable) } else { AlertDialogDefaults.buttonStackContentPadding(isScrollable) } }

The 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.

properties: DialogProperties = DialogProperties()

An optional DialogProperties object for configuring the dialog's behavior.

content: (TransformingLazyColumnScope.() -> Unit)? = null

A slot for additional content, displayed within a scrollable TransformingLazyColumn. To ensure that your custom items animate consistently with the rest of the dialog, we recommend applying a TransformationSpec to every item.

@Composable
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
): Unit

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.

This overload has 2 IconButtons for confirmation and cancellation, placed horizontally at the bottom of the dialog. It should be used when the user will be presented with a binary decision, to either confirm or dismiss an action.

Where user input is not required, such as displaying a transient success or failure message, use ConfirmationDialog, SuccessConfirmationDialog or FailureConfirmationDialog instead.

AlertDialog now additionally offers an equivalent overload using TransformingLazyColumn, which is recommended to achieve a consistent Material 3 scrolling experience throughout your app

Example of an AlertDialog with an icon, title and two buttons to confirm and dismiss:

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.size
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.AccountCircle
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.wear.compose.material3.AlertDialog
import androidx.wear.compose.material3.AlertDialogDefaults
import androidx.wear.compose.material3.Button
import androidx.wear.compose.material3.FilledTonalButton
import androidx.wear.compose.material3.Icon
import androidx.wear.compose.material3.MaterialTheme
import androidx.wear.compose.material3.Text

var showDialog by remember { mutableStateOf(false) }
Box(Modifier.fillMaxSize()) {
    FilledTonalButton(
        modifier = Modifier.align(Alignment.Center),
        onClick = { showDialog = true },
        label = { Text("Show Dialog") },
    )
}
AlertDialog(
    visible = showDialog,
    onDismissRequest = { showDialog = false },
    icon = {
        Icon(
            Icons.Rounded.AccountCircle,
            modifier = Modifier.size(32.dp),
            contentDescription = null,
            tint = MaterialTheme.colorScheme.primary,
        )
    },
    title = { Text("Enable Battery Saver Mode?") },
    text = { Text("Your battery is low. Turn on battery saver.") },
    confirmButton = {
        AlertDialogDefaults.ConfirmButton(
            onClick = {
                // Perform confirm action here
                showDialog = false
            }
        )
    },
    dismissButton = {
        AlertDialogDefaults.DismissButton(
            onClick = {
                // Perform dismiss action here
                showDialog = false
            }
        )
    },
) {
    item { Text(text = "You can configure battery saver mode in the setting menu.") }
    item { Button(onClick = {}) { Text(text = "Go to settings") } }
}
Parameters
visible: Boolean

A boolean indicating whether the dialog should be displayed.

onDismissRequest: () -> Unit

A 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.

confirmButton: @Composable RowScope.() -> Unit

A 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.

title: @Composable () -> Unit

A 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.

modifier: Modifier = Modifier

Modifier to be applied to the dialog content.

dismissButton: @Composable RowScope.() -> Unit = { AlertDialogDefaults.DismissButton(onDismissRequest) }

A 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.

icon: (@Composable () -> Unit)? = null

Optional slot for an icon to be shown at the top of the dialog.

text: (@Composable () -> Unit)? = null

Optional 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.

verticalArrangement: Arrangement.Vertical = AlertDialogDefaults.VerticalArrangement

The 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.

contentPadding: PaddingValues = if (icon != null) { AlertDialogDefaults.confirmDismissWithIconContentPadding() } else { AlertDialogDefaults.confirmDismissContentPadding() }

The 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.

properties: DialogProperties = DialogProperties()

An optional DialogProperties object for configuring the dialog's behavior.

content: (ScalingLazyListScope.() -> Unit)? = null

A slot for additional content, displayed within a scrollable ScalingLazyColumn.

@Composable
fun AlertDialog(
    visible: Boolean,
    onDismissRequest: () -> Unit,
    edgeButton: @Composable BoxScope.() -> Unit,
    title: @Composable () -> Unit,
    transformationSpec: TransformationSpec,
    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: (TransformingLazyColumnScope.() -> Unit)? = null
): Unit

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

This overload has a single slot for a confirm EdgeButton at the bottom of the dialog, which should be used when the user will be presented with a single acknowledgement. It uses a TransformationSpec for advanced control over transformations of scrolling content.

Where user input is not required, such as displaying a transient success or failure message, use ConfirmationDialog, SuccessConfirmationDialog or FailureConfirmationDialog instead.

The transformationSpec parameter enables the use of a TransformingLazyColumn internally for advanced control over transformations of scrolling content, which can not be achieved with ScalingLazyColumn.

Example of an AlertDialog with an icon, title, text and bottom EdgeButton:

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.size
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.AccountCircle
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.wear.compose.material3.AlertDialog
import androidx.wear.compose.material3.AlertDialogDefaults
import androidx.wear.compose.material3.Button
import androidx.wear.compose.material3.FilledTonalButton
import androidx.wear.compose.material3.Icon
import androidx.wear.compose.material3.MaterialTheme
import androidx.wear.compose.material3.Text
import androidx.wear.compose.material3.lazy.rememberTransformationSpec

var showDialog by remember { mutableStateOf(false) }

Box(Modifier.fillMaxSize()) {
    FilledTonalButton(
        modifier = Modifier.align(Alignment.Center),
        onClick = { showDialog = true },
        label = { Text("Show Dialog") },
    )
}

AlertDialog(
    visible = showDialog,
    onDismissRequest = { showDialog = false },
    icon = {
        Icon(
            Icons.Rounded.AccountCircle,
            modifier = Modifier.size(32.dp),
            contentDescription = null,
            tint = MaterialTheme.colorScheme.primary,
        )
    },
    title = { Text("Mobile network is not currently available") },
    text = { Text("Please try again later or check your network settings.") },
    transformationSpec = rememberTransformationSpec(),
    edgeButton = {
        AlertDialogDefaults.EdgeButton(
            onClick = {
                // Perform confirm action here
                showDialog = false
            }
        )
    },
)

Example of an AlertDialog with content groups and a bottom EdgeButton:

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.wear.compose.material3.AlertDialog
import androidx.wear.compose.material3.AlertDialogDefaults
import androidx.wear.compose.material3.Button
import androidx.wear.compose.material3.FilledTonalButton
import androidx.wear.compose.material3.SurfaceTransformation
import androidx.wear.compose.material3.SwitchButton
import androidx.wear.compose.material3.Text
import androidx.wear.compose.material3.lazy.rememberTransformationSpec
import androidx.wear.compose.material3.lazy.transformedHeight

var showDialog by remember { mutableStateOf(false) }
var weatherEnabled by remember { mutableStateOf(false) }
var calendarEnabled by remember { mutableStateOf(false) }
val transformationSpec = rememberTransformationSpec()

Box(Modifier.fillMaxSize()) {
    FilledTonalButton(
        modifier = Modifier.align(Alignment.Center),
        onClick = { showDialog = true },
        label = { Text("Show Dialog") },
    )
}
AlertDialog(
    visible = showDialog,
    onDismissRequest = { showDialog = false },
    title = { Text("Share your location") },
    text = { Text(" The following apps have asked you to share your location") },
    transformationSpec = transformationSpec,
    edgeButton = {
        AlertDialogDefaults.EdgeButton(
            onClick = {
                // Perform confirm action here
                showDialog = false
            }
        ) {
            Text("Share once")
        }
    },
) {
    item {
        SwitchButton(
            modifier = Modifier.fillMaxWidth().transformedHeight(this, transformationSpec),
            checked = weatherEnabled,
            onCheckedChange = { weatherEnabled = it },
            label = { Text("Weather") },
            transformation = SurfaceTransformation(transformationSpec),
        )
    }
    item {
        SwitchButton(
            modifier = Modifier.fillMaxWidth().transformedHeight(this, transformationSpec),
            checked = calendarEnabled,
            onCheckedChange = { calendarEnabled = it },
            label = { Text("Calendar") },
            transformation = SurfaceTransformation(transformationSpec),
        )
    }
    item { AlertDialogDefaults.GroupSeparator() }
    item {
        FilledTonalButton(
            modifier = Modifier.fillMaxWidth().transformedHeight(this, transformationSpec),
            onClick = {},
            label = { Text(modifier = Modifier.fillMaxWidth(), text = "Never share") },
            transformation = SurfaceTransformation(transformationSpec),
        )
    }
    item {
        FilledTonalButton(
            modifier = Modifier.fillMaxWidth().transformedHeight(this, transformationSpec),
            onClick = {},
            label = { Text(modifier = Modifier.fillMaxWidth(), text = "Share always") },
            transformation = SurfaceTransformation(transformationSpec),
        )
    }
}
Parameters
visible: Boolean

A boolean indicating whether the dialog should be displayed.

onDismissRequest: () -> Unit

A 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.

edgeButton: @Composable BoxScope.() -> Unit

Slot 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.

title: @Composable () -> Unit

A 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.

transformationSpec: TransformationSpec

A spec that defines how items inside the TransformingLazyColumn transform and animate as they are scrolled. It is recommended to create a spec using rememberTransformationSpec. This parameter is the key differentiator from the standard AlertDialog overload, which uses a ScalingLazyColumn without per-item customizable animations. The provided transformationSpec is automatically applied only to the dialog's standard components (title, text, and buttons), while additional items in content lambda need to be handled manually, by applying a TransformationSpec to each of them. First item has a fixed spec, with a reduced transition area, so that the top item does not appear scaled or faded when the dialog is initially displayed.

modifier: Modifier = Modifier

Modifier to be applied to the dialog content.

icon: (@Composable () -> Unit)? = null

Optional slot for an icon to be shown at the top of the dialog.

text: (@Composable () -> Unit)? = null

Optional 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.

verticalArrangement: Arrangement.Vertical = AlertDialogDefaults.VerticalArrangement

The 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.

contentPadding: PaddingValues = if (icon != null) { AlertDialogDefaults.contentWithIconPadding() } else { AlertDialogDefaults.contentPadding() }

The 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.

properties: DialogProperties = DialogProperties()

An optional DialogProperties object for configuring the dialog's behavior.

content: (TransformingLazyColumnScope.() -> Unit)? = null

A slot for additional content, displayed within a scrollable TransformingLazyColumn. 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. To ensure that your custom items animate consistently with the rest of the dialog, we recommend applying a TransformationSpec to each of them - see samples.

@Composable
fun AlertDialog(
    visible: Boolean,
    onDismissRequest: () -> Unit,
    confirmButton: @Composable RowScope.() -> Unit,
    title: @Composable () -> Unit,
    transformationSpec: TransformationSpec,
    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: (TransformingLazyColumnScope.() -> Unit)? = null
): Unit

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.

This overload has 2 IconButtons for confirmation and cancellation and it uses a TransformationSpec for advanced control over transformations of scrolling content.

The confirmation buttons are centered horizontally at the bottom of the dialog. This overload should be used when the user will be presented with a binary decision, to either confirm or dismiss an action. Where user input is not required, such as displaying a transient success or failure message, use ConfirmationDialog, SuccessConfirmationDialog or FailureConfirmationDialog instead.

The transformationSpec parameter enables the use of a TransformingLazyColumn internally for advanced control over transformations of scrolling content, which can not be achieved with ScalingLazyColumn.

Example of an AlertDialog with an icon, title and two buttons to confirm and dismiss:

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.size
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.AccountCircle
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.unit.dp
import androidx.wear.compose.material3.AlertDialog
import androidx.wear.compose.material3.AlertDialogDefaults
import androidx.wear.compose.material3.Button
import androidx.wear.compose.material3.FilledTonalButton
import androidx.wear.compose.material3.Icon
import androidx.wear.compose.material3.MaterialTheme
import androidx.wear.compose.material3.SurfaceTransformation
import androidx.wear.compose.material3.Text
import androidx.wear.compose.material3.lazy.rememberTransformationSpec
import androidx.wear.compose.material3.lazy.transformedHeight

var showDialog by remember { mutableStateOf(false) }
val transformationSpec = rememberTransformationSpec()

Box(Modifier.fillMaxSize()) {
    FilledTonalButton(
        modifier = Modifier.align(Alignment.Center),
        onClick = { showDialog = true },
        label = { Text("Show Dialog") },
    )
}
AlertDialog(
    visible = showDialog,
    onDismissRequest = { showDialog = false },
    icon = {
        Icon(
            Icons.Rounded.AccountCircle,
            modifier = Modifier.size(32.dp),
            contentDescription = null,
            tint = MaterialTheme.colorScheme.primary,
        )
    },
    title = { Text("Enable Battery Saver Mode?") },
    text = { Text("Your battery is low. Turn on battery saver.") },
    transformationSpec = transformationSpec,
    confirmButton = {
        AlertDialogDefaults.ConfirmButton(
            onClick = {
                // Perform confirm action here
                showDialog = false
            }
        )
    },
    dismissButton = {
        AlertDialogDefaults.DismissButton(
            onClick = {
                // Perform dismiss action here
                showDialog = false
            }
        )
    },
) {
    item {
        Text(
            modifier =
                Modifier.transformedHeight(this, transformationSpec).graphicsLayer {
                    with(SurfaceTransformation(transformationSpec)) {
                        applyContentTransformation()
                        applyContainerTransformation()
                    }
                },
            text = "You can configure battery saver mode in the setting menu.",
        )
    }
    item {
        Button(
            modifier = Modifier.transformedHeight(this, transformationSpec),
            transformation = SurfaceTransformation(transformationSpec),
            onClick = {},
        ) {
            Text(text = "Go to settings")
        }
    }
}
Parameters
visible: Boolean

A boolean indicating whether the dialog should be displayed.

onDismissRequest: () -> Unit

A 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.

confirmButton: @Composable RowScope.() -> Unit

A 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.

title: @Composable () -> Unit

A 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.

transformationSpec: TransformationSpec

A spec that defines how items inside the TransformingLazyColumn transform and animate as they are scrolled. It is recommended to create a spec using rememberTransformationSpec. This parameter is the key differentiator from the standard AlertDialog overload, which uses a ScalingLazyColumn without per-item customizable animations. The provided transformationSpec is automatically applied only to the dialog's standard components (title, text, and buttons), while additional items in content lambda need to be handled manually, by applying a TransformationSpec to each of them. First item has a fixed spec, with a reduced transition area, so that the top item does not appear scaled or faded when the dialog is initially displayed.

modifier: Modifier = Modifier

Modifier to be applied to the dialog content.

dismissButton: @Composable RowScope.() -> Unit = { AlertDialogDefaults.DismissButton(onDismissRequest) }

A 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.

icon: (@Composable () -> Unit)? = null

Optional slot for an icon to be shown at the top of the dialog.

text: (@Composable () -> Unit)? = null

Optional 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.

verticalArrangement: Arrangement.Vertical = AlertDialogDefaults.VerticalArrangement

The 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.

contentPadding: PaddingValues = if (icon != null) { AlertDialogDefaults.confirmDismissWithIconContentPadding() } else { AlertDialogDefaults.confirmDismissContentPadding() }

The 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.

properties: DialogProperties = DialogProperties()

An optional DialogProperties object for configuring the dialog's behavior.

content: (TransformingLazyColumnScope.() -> Unit)? = null

A slot for additional content, displayed within a scrollable TransformingLazyColumn. To ensure that your custom items animate consistently with the rest of the dialog, we recommend applying a TransformationSpec to every item.