I want to show alert dialog on button press in Jetpeck Compose
This is my code but i dont know how to create alert dialog.
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
MaterialTheme {
Column {
showSaveButton()
}
}
}
}
@Composable
fun showSaveButton(){
Button("Save",
onClick = {
// when user click on save button i want to open dialog
}
)
}
}
Here is simple example of alert dialogue:-
@Composable
fun showSaveDialog() {
AlertDialog(
onCloseRequest = {
},
title = {
Text(text = "Alert Dialog")
},
text = {
Text("Are you sure ?")
},
confirmButton = {
Button("Yes", onClick = {
})
}
)
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.