| /* |
| * Copyright 2021 The Android Open Source Project |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| |
| package androidx.compose.material3.samples |
| |
| // TODO(b/198216553): Update to use Material 3 TextButton. |
| import androidx.annotation.Sampled |
| import androidx.compose.material.TextButton |
| import androidx.compose.material.icons.Icons |
| import androidx.compose.material.icons.filled.Favorite |
| import androidx.compose.material3.AlertDialog |
| import androidx.compose.material3.Icon |
| import androidx.compose.material3.Text |
| import androidx.compose.runtime.Composable |
| import androidx.compose.runtime.mutableStateOf |
| import androidx.compose.runtime.remember |
| |
| @Sampled |
| @Composable |
| fun AlertDialogSample() { |
| val openDialog = remember { mutableStateOf(true) } |
| |
| 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 |
| // onDismissRequest. |
| openDialog.value = false |
| }, |
| title = { |
| Text(text = "Title") |
| }, |
| text = { |
| Text(text = "Turned on by default") |
| }, |
| confirmButton = { |
| TextButton( |
| onClick = { |
| openDialog.value = false |
| } |
| ) { |
| Text("Confirm") |
| } |
| }, |
| dismissButton = { |
| TextButton( |
| onClick = { |
| openDialog.value = false |
| } |
| ) { |
| Text("Dismiss") |
| } |
| } |
| ) |
| } |
| } |
| |
| @Sampled |
| @Composable |
| fun AlertDialogWithIconSample() { |
| val openDialog = remember { mutableStateOf(true) } |
| |
| 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 |
| // onDismissRequest. |
| openDialog.value = false |
| }, |
| icon = { Icon(Icons.Filled.Favorite, contentDescription = null) }, |
| title = { |
| Text(text = "Title") |
| }, |
| text = { |
| Text( |
| "This area typically contains the supportive text " + |
| "which presents the details regarding the Dialog's purpose." |
| ) |
| }, |
| confirmButton = { |
| TextButton( |
| onClick = { |
| openDialog.value = false |
| } |
| ) { |
| Text("Confirm") |
| } |
| }, |
| dismissButton = { |
| TextButton( |
| onClick = { |
| openDialog.value = false |
| } |
| ) { |
| Text("Dismiss") |
| } |
| } |
| ) |
| } |
| } |