AlertDialogDefaults

object AlertDialogDefaults


Contains the default values used by AlertDialog

Summary

Constants

const Float

Default gestureVisibilityThreshold for ConfirmButton, requiring the button to be more than 90% visible before the primary one-handed gesture is active.

const Float

Recommended gestureVisibilityThreshold for EdgeButton when the primary one-handed gesture is enabled.

const Float

Value for gestureVisibilityThreshold on EdgeButton and ConfirmButton that disables the primary one-handed gesture on the button.

Public functions

Unit
@Composable
ConfirmButton(
    onClick: () -> Unit,
    modifier: Modifier,
    colors: IconButtonColors,
    content: @Composable RowScope.() -> Unit
)

Default composable for the confirm button in an AlertDialog, which supports the primary one-handed gesture (OneHandedGestureAction.Primary) when the button is sufficiently visible.

Unit
@Composable
ConfirmButton(
    onClick: () -> Unit,
    gestureVisibilityThreshold: @FloatRange(from = 0.0, to = 1.0) Float,
    modifier: Modifier,
    onGestureLabel: String?,
    colors: IconButtonColors,
    content: @Composable RowScope.() -> Unit
)

Composable for the confirm button in an AlertDialog with a configurable visibility threshold for the primary one-handed gesture (OneHandedGestureAction.Primary).

Unit
@Composable
DismissButton(
    onClick: () -> Unit,
    modifier: Modifier,
    colors: IconButtonColors,
    content: @Composable RowScope.() -> Unit
)

Default composable for the dismiss button in an AlertDialog.

Unit
@Composable
EdgeButton(
    onClick: () -> Unit,
    modifier: Modifier,
    colors: ButtonColors,
    content: @Composable RowScope.() -> Unit
)

Default composable for the edge button in an AlertDialog.

Unit
@Composable
EdgeButton(
    onClick: () -> Unit,
    gestureVisibilityThreshold: @FloatRange(from = 0.0, to = 1.0) Float,
    modifier: Modifier,
    onGestureLabel: String?,
    colors: ButtonColors,
    content: @Composable RowScope.() -> Unit
)

Composable for the edge button in an AlertDialog that supports the primary one-handed gesture (OneHandedGestureAction.Primary).

Unit

Separator for the AlertDialog.

PaddingValues

The padding to apply around the content for the AlertDialog variation using TransformingLazyColumn, without an icon, and with a stack of buttons for options.

PaddingValues

The padding to apply around the content for the AlertDialog variation using TransformingLazyColumn, with icon, and with a stack of buttons for options.

PaddingValues

The padding to apply around the content for the AlertDialog variation with confirm dismiss buttons and no icon content.

PaddingValues

The padding to apply around the content for the AlertDialog variation when an icon is provided and with confirm dismiss buttons.

PaddingValues

The padding to apply around the content for the AlertDialog with either a stack of buttons (no confirm or dismiss buttons) or an EdgeButton, and when there is no icon.

PaddingValues

The padding to apply around the content for the AlertDialog with either a stack of buttons (no confirm or dismiss buttons) or an EdgeButton, and when there is an icon.

Public properties

@Composable RowScope.() -> Unit

Default icon for the confirm button.

@Composable RowScope.() -> Unit

Default icon for the dismiss button.

Arrangement.Vertical

Default vertical arrangement for an AlertDialog.

Constants

ConfirmButtonGestureVisibilityThreshold

Added in 1.8.0-alpha04
const val ConfirmButtonGestureVisibilityThreshold = 0.9f: Float

Default gestureVisibilityThreshold for ConfirmButton, requiring the button to be more than 90% visible before the primary one-handed gesture is active.

EdgeButtonGestureVisibilityThreshold

Added in 1.8.0-alpha04
const val EdgeButtonGestureVisibilityThreshold = 0.9f: Float

Recommended gestureVisibilityThreshold for EdgeButton when the primary one-handed gesture is enabled.

GestureDisabled

Added in 1.8.0-alpha04
const val GestureDisabled = 0.0f: Float

Value for gestureVisibilityThreshold on EdgeButton and ConfirmButton that disables the primary one-handed gesture on the button.

Public functions

ConfirmButton

Added in 1.5.0
@Composable
fun ConfirmButton(
    onClick: () -> Unit,
    modifier: Modifier = Modifier,
    colors: IconButtonColors = IconButtonDefaults.filledIconButtonColors(),
    content: @Composable RowScope.() -> Unit = ConfirmIcon
): Unit

Default composable for the confirm button in an AlertDialog, which supports the primary one-handed gesture (OneHandedGestureAction.Primary) when the button is sufficiently visible. Should be used with AlertDialog overload which has 2 button slots to confirm or dismiss the action.

Parameters
onClick: () -> Unit

The callback to be invoked when the button is clicked or triggered via gesture.

modifier: Modifier = Modifier

The Modifier to be applied to the button.

colors: IconButtonColors = IconButtonDefaults.filledIconButtonColors()

The IconButtonColors to be used for the button.

content: @Composable RowScope.() -> Unit = ConfirmIcon

The composable content of the button. Defaults to ConfirmIcon.

ConfirmButton

@Composable
fun ConfirmButton(
    onClick: () -> Unit,
    gestureVisibilityThreshold: @FloatRange(from = 0.0, to = 1.0) Float,
    modifier: Modifier = Modifier,
    onGestureLabel: String? = stringResource( R.string.one_handed_gesture_alert_dialog_primary_action_confirm_accessibility_text ),
    colors: IconButtonColors = IconButtonDefaults.filledIconButtonColors(),
    content: @Composable RowScope.() -> Unit = ConfirmIcon
): Unit

Composable for the confirm button in an AlertDialog with a configurable visibility threshold for the primary one-handed gesture (OneHandedGestureAction.Primary). Should be used with the AlertDialog overload which has 2 button slots to confirm or dismiss the action.

Note: Gesture recognition can also be disabled across a component hierarchy by providing false to androidx.wear.compose.material3.onehandedgesture.LocalOneHandedGestureEnabled.

Example of an AlertDialog where the one-handed gesture on ConfirmButton is disabled by setting gestureVisibilityThreshold to GestureDisabled:

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("Reset all settings?") },
    text = { Text("This action cannot be undone.") },
    confirmButton = {
        AlertDialogDefaults.ConfirmButton(
            onClick = {
                // Perform confirm action here
                showDialog = false
            },
            gestureVisibilityThreshold = AlertDialogDefaults.GestureDisabled,
        )
    },
    dismissButton = {
        AlertDialogDefaults.DismissButton(
            onClick = {
                // Perform dismiss action here
                showDialog = false
            }
        )
    },
)
Parameters
onClick: () -> Unit

The callback to be invoked when the button is clicked or triggered via gesture.

gestureVisibilityThreshold: @FloatRange(from = 0.0, to = 1.0) Float

The minimum fraction of the button, between 0.0 and 1.0, that must be visible in the viewport before the primary one-handed gesture is active. For values between 0.0 and 1.0, the gesture is active once the visible fraction of the button exceeds the specified threshold. A value of 1f requires the entire button to be visible, whereas GestureDisabled (0f) disables the gesture on the button. ConfirmButtonGestureVisibilityThreshold is used by default in the ConfirmButton overload that does not take a gestureVisibilityThreshold parameter.

modifier: Modifier = Modifier

The Modifier to be applied to the button.

onGestureLabel: String? = stringResource( R.string.one_handed_gesture_alert_dialog_primary_action_confirm_accessibility_text )

Semantic label used by accessibility services to describe the purpose of the one-handed gesture. Defaults to localized "confirm" text to match ConfirmIcon, and should be customized when content represents a different action. This is highly recommended for ensuring that users with screen readers understand what action will be performed - if null, no accessibility announcement is made for the one-handed gesture.

colors: IconButtonColors = IconButtonDefaults.filledIconButtonColors()

The IconButtonColors to be used for the button.

content: @Composable RowScope.() -> Unit = ConfirmIcon

The composable content of the button. Defaults to ConfirmIcon.

DismissButton

Added in 1.5.0
@Composable
fun DismissButton(
    onClick: () -> Unit,
    modifier: Modifier = Modifier,
    colors: IconButtonColors = IconButtonDefaults.filledTonalIconButtonColors(),
    content: @Composable RowScope.() -> Unit = DismissIcon
): Unit

Default composable for the dismiss button in an AlertDialog. Should be used with AlertDialog overload which has 2 button slots to confirm or dismiss the action.

Parameters
onClick: () -> Unit

The callback to be invoked when the button is clicked.

modifier: Modifier = Modifier

The Modifier to be applied to the button.

colors: IconButtonColors = IconButtonDefaults.filledTonalIconButtonColors()

The IconButtonColors to be used for the button.

content: @Composable RowScope.() -> Unit = DismissIcon

The composable content of the button. Defaults to DismissIcon.

EdgeButton

Added in 1.5.0
@Composable
fun EdgeButton(
    onClick: () -> Unit,
    modifier: Modifier = Modifier,
    colors: ButtonColors = ButtonDefaults.buttonColors(),
    content: @Composable RowScope.() -> Unit = ConfirmIcon
): Unit

Default composable for the edge button in an AlertDialog. This is a medium sized EdgeButton. Should be used with AlertDialog overload which contains a single edgeButton slot.

Parameters
onClick: () -> Unit

The callback to be invoked when the button is clicked.

modifier: Modifier = Modifier

The Modifier to be applied to the button.

colors: ButtonColors = ButtonDefaults.buttonColors()

The ButtonColors to be used for the button.

content: @Composable RowScope.() -> Unit = ConfirmIcon

The composable content of the button. Defaults to ConfirmIcon.

EdgeButton

@Composable
fun EdgeButton(
    onClick: () -> Unit,
    gestureVisibilityThreshold: @FloatRange(from = 0.0, to = 1.0) Float,
    modifier: Modifier = Modifier,
    onGestureLabel: String? = stringResource( R.string.one_handed_gesture_alert_dialog_primary_action_confirm_accessibility_text ),
    colors: ButtonColors = ButtonDefaults.buttonColors(),
    content: @Composable RowScope.() -> Unit = ConfirmIcon
): Unit

Composable for the edge button in an AlertDialog that supports the primary one-handed gesture (OneHandedGestureAction.Primary). This is a medium sized EdgeButton and should be used with the AlertDialog overload that contains a single edgeButton slot when primary gesture activation is desired.

Note: Gesture recognition can be disabled across a component hierarchy by providing false to androidx.wear.compose.material3.onehandedgesture.LocalOneHandedGestureEnabled.

Example of an AlertDialog with a bottom EdgeButton supporting the primary one-handed gesture:

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
            },
            gestureVisibilityThreshold =
                AlertDialogDefaults.EdgeButtonGestureVisibilityThreshold,
        )
    },
)
Parameters
onClick: () -> Unit

The callback to be invoked when the button is clicked or triggered via gesture.

gestureVisibilityThreshold: @FloatRange(from = 0.0, to = 1.0) Float

The minimum fraction of the button's height, between 0.0 and 1.0, that must be visible before the primary one-handed gesture is active. For values between 0.0 and 1.0, the gesture is active once the visible fraction of the button exceeds the specified threshold. A value of 1f requires the button to reach its full height, whereas GestureDisabled (0f) disables the gesture on the button. Because EdgeButton fades its content out when partially collapsed, EdgeButtonGestureVisibilityThreshold (or a threshold of at least 0.5f) is recommended so the button content and gesture indicator are visible when triggered.

modifier: Modifier = Modifier

The Modifier to be applied to the button.

onGestureLabel: String? = stringResource( R.string.one_handed_gesture_alert_dialog_primary_action_confirm_accessibility_text )

Semantic label used by accessibility services to describe the purpose of the one-handed gesture. Defaults to localized "confirm" text to match ConfirmIcon, and should be customized when content represents a different action. This is highly recommended for ensuring that users with screen readers understand what action will be performed - if null, no accessibility announcement is made for the one-handed gesture.

colors: ButtonColors = ButtonDefaults.buttonColors()

The ButtonColors to be used for the button.

content: @Composable RowScope.() -> Unit = ConfirmIcon

The composable content of the button. Defaults to ConfirmIcon.

GroupSeparator

Added in 1.5.0
@Composable
fun GroupSeparator(): Unit

Separator for the AlertDialog. Should be used inside AlertDialog content for splitting groups of elements.

buttonStackContentPadding

Added in 1.6.0
@Composable
fun buttonStackContentPadding(isScrollable: Boolean): PaddingValues

The padding to apply around the content for the AlertDialog variation using TransformingLazyColumn, without an icon, and with a stack of buttons for options. Bottom padding is calculated based on the provided isScrollable parameter, which favors the use of a bigger padding for scrollable content and a smaller one for fixed content.

buttonStackWithIconContentPadding

Added in 1.6.0
@Composable
fun buttonStackWithIconContentPadding(isScrollable: Boolean): PaddingValues

The padding to apply around the content for the AlertDialog variation using TransformingLazyColumn, with icon, and with a stack of buttons for options. Bottom padding is calculated based on the provided isScrollable parameter, which favors the use of a bigger padding for scrollable content and a smaller one for fixed content.

confirmDismissContentPadding

Added in 1.5.0
@Composable
fun confirmDismissContentPadding(): PaddingValues

The padding to apply around the content for the AlertDialog variation with confirm dismiss buttons and no icon content.

confirmDismissWithIconContentPadding

Added in 1.5.0
@Composable
fun confirmDismissWithIconContentPadding(): PaddingValues

The padding to apply around the content for the AlertDialog variation when an icon is provided and with confirm dismiss buttons.

contentPadding

Added in 1.5.0
@Composable
fun contentPadding(): PaddingValues

The padding to apply around the content for the AlertDialog with either a stack of buttons (no confirm or dismiss buttons) or an EdgeButton, and when there is no icon. For the EdgeButton variation, the bottom padding is ignored.

contentWithIconPadding

Added in 1.5.0
@Composable
fun contentWithIconPadding(): PaddingValues

The padding to apply around the content for the AlertDialog with either a stack of buttons (no confirm or dismiss buttons) or an EdgeButton, and when there is an icon. For the EdgeButton variation, the bottom padding is ignored.

Public properties

ConfirmIcon

Added in 1.5.0
val ConfirmIcon: @Composable RowScope.() -> Unit

Default icon for the confirm button.

DismissIcon

Added in 1.5.0
val DismissIcon: @Composable RowScope.() -> Unit

Default icon for the dismiss button.

VerticalArrangement

Added in 1.5.0
val VerticalArrangement: Arrangement.Vertical

Default vertical arrangement for an AlertDialog.