---
title: "AlertDialog"
description: "Displays an urgent prompt requiring the user to acknowledge or take an action."
type: "component"
lastmod: "2026-09-24"
---
## API Reference

### AlertDialog

> Source set: Android

```kotlin
@Composable
public fun AlertDialog(
    onDismissRequest: () -> Unit,
    confirmButton: @Composable () -> Unit,
    text: @Composable () -> Unit,
    modifier: Modifier = Modifier,
    dismissButton: @Composable (() -> Unit)? = null,
    icon: @Composable (() -> Unit)? = null,
    title: @Composable (() -> Unit)? = null,
    shape: Shape = AlertDialogDefaults.shape,
    containerColor: Color = AlertDialogDefaults.containerColor,
    contentColor: Color = AlertDialogDefaults.contentColor(containerColor),
    contentPadding: PaddingValues = AlertDialogDefaults.contentPadding,
)
```

#### Parameters

| | |
| --- | --- |
| onDismissRequest | called when the user tries to dismiss the dialog |
| confirmButton | button used to confirm or accept the action. This will be the first button shown and takes focus upon the dialog being opened |
| text | body text providing additional details or explanation for the dialog, placed below the `title` |
| modifier | the [Modifier](/jetpack-compose/androidx.compose.ui/ui/interfaces/Modifier) to be applied to the dialog |
| dismissButton | optional button used to dismiss or cancel the alert dialog |
| icon | optional icon displayed at the top of the dialog, above the `title` |
| title | optional title displaying the primary headline of the dialog, placed below the [icon](/jetpack-compose/androidx.xr.glimmer/glimmer/components/Icon) and above the [text](/jetpack-compose/androidx.xr.glimmer/glimmer/components/Text) |
| shape | the [Shape](/jetpack-compose/androidx.compose.ui/ui-graphics/interfaces/Shape) of the dialog container |
| containerColor | the background [Color](/jetpack-compose/androidx.compose.ui/ui-graphics/classes/Color) of the dialog container |
| contentColor | the default [Color](/jetpack-compose/androidx.compose.ui/ui-graphics/classes/Color) for content inside the dialog container |
| contentPadding | the spacing values to apply internally between the container and the content |

## Code Examples

### AlertDialogSample

```kotlin
@Sampled
@Composable
fun AlertDialogSample() {
    var showDialog by remember { mutableStateOf(true) }

    if (showDialog) {
        AlertDialog(
            onDismissRequest = { showDialog = false },
            confirmButton = { Button(onClick = { /* confirm action */ }) { Text("Confirm") } },
            dismissButton = { Button(onClick = { showDialog = false }) { Text("Dismiss") } },
            icon = { Icon(imageVector = FavoriteIcon, contentDescription = "Alert icon") },
            title = { Text("Title") },
            text = { Text("This is an alert dialog with options to confirm or dismiss.") },
        )
    }
}
```

### AlertDialogConfirmOnlySample

```kotlin
@Sampled
@Composable
fun AlertDialogConfirmOnlySample() {
    var showDialog by remember { mutableStateOf(true) }

    if (showDialog) {
        AlertDialog(
            onDismissRequest = { showDialog = false },
            confirmButton = { Button(onClick = { showDialog = false }) { Text("OK") } },
            icon = {
                Icon(
                    imageVector = OutlinedFavoriteIcon,
                    contentDescription = "Favorite icon",
                )
            },
            title = { Text("Title") },
            text = { Text("This is an alert dialog with only an option to dismiss.") },
        )
    }
}
```
