Compose Component

AlertDialog

Displays an urgent prompt requiring the user to acknowledge or take an action.

AlertDialogSample

@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

@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.") },
        )
    }
}
Jetpack Compose beyond MaterialFree components, screens and templates for apps that don’t look like Google’s. Copy them into your app, or let your coding agent add them.Browse for free

Content updated: