69 lines
1.9 KiB
Markdown
69 lines
1.9 KiB
Markdown
<!---
|
|
This is the API of version 1.2.0
|
|
-->
|
|
|
|
# AlertDialog
|
|
|
|
Alert dialog is a Dialog which interrupts the user with urgent information, details or actions.
|
|
|
|
<p align="center">
|
|
<img src ="{{ site.images }}/material/alertdialog/AlertDialogSample.png" height=100 width=300/>
|
|
</p>
|
|
|
|
```kotlin
|
|
@Composable
|
|
fun AlertDialogSample() {
|
|
MaterialTheme {
|
|
Column {
|
|
val openDialog = remember { mutableStateOf(false) }
|
|
|
|
Button(onClick = {
|
|
openDialog.value = true
|
|
}) {
|
|
Text("Click me")
|
|
}
|
|
|
|
if (openDialog.value) {
|
|
|
|
AlertDialog(
|
|
onDismissRequest = {
|
|
// Dismiss the dialog when the user clicks outside the dialog or on the back
|
|
// button. If you want to disable that functionality, simply use an empty
|
|
// onCloseRequest.
|
|
openDialog.value = false
|
|
},
|
|
title = {
|
|
Text(text = "Dialog Title")
|
|
},
|
|
text = {
|
|
Text("Here is a text ")
|
|
},
|
|
confirmButton = {
|
|
Button(
|
|
|
|
onClick = {
|
|
openDialog.value = false
|
|
}) {
|
|
Text("This is the Confirm Button")
|
|
}
|
|
},
|
|
dismissButton = {
|
|
Button(
|
|
|
|
onClick = {
|
|
openDialog.value = false
|
|
}) {
|
|
Text("This is the dismiss Button")
|
|
}
|
|
}
|
|
)
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
```
|
|
|
|
## See also:
|
|
* [Full Example Code]({{ site.samplefolder }}/material/alertdialog/AlertDialogSample.kt)
|