🌈 Create new beautiful Compose Gradients with our new wesite ->

AlertDialog

AlertDialog preview
Kotlin
@Composable

fun AlertDialogWithConfirmAndDismissSample() {
    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") } }
    }
}