Created
May 7, 2025 08:50
-
-
Save Sprajapati123/63d5586a00f837cbf974ab822a456707 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.example.c36b | |
| import androidx.compose.foundation.layout.Column | |
| import androidx.compose.material3.AlertDialog | |
| import androidx.compose.material3.Button | |
| import androidx.compose.material3.Text | |
| import androidx.compose.runtime.Composable | |
| import androidx.compose.runtime.getValue | |
| import androidx.compose.runtime.mutableStateOf | |
| import androidx.compose.runtime.remember | |
| import androidx.compose.runtime.setValue | |
| @Composable | |
| fun AlertDialogBody() { | |
| var showDialog by remember { mutableStateOf(false) } | |
| Column { | |
| // Trigger to show the dialog | |
| Button(onClick = { showDialog = true }) { | |
| Text("Show AlertDialog") | |
| } | |
| if (showDialog) { | |
| AlertDialog( | |
| onDismissRequest = { | |
| showDialog = false | |
| }, // dismiss when clicked outside | |
| confirmButton = { | |
| Button(onClick = { | |
| // Confirm action | |
| showDialog = false | |
| }) { | |
| Text("OK") | |
| } | |
| }, | |
| dismissButton = { | |
| Button(onClick = { | |
| // Cancel action | |
| showDialog = false | |
| }) { | |
| Text("Cancel") | |
| } | |
| }, | |
| title = { Text(text = "Alert Title") }, | |
| text = { Text("This is an alert dialog message.") } | |
| ) | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment