1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| @Composable fun SnackbarDemo() { Column { val snackbarVisibilityState = remember { mutableStateOf(false) } Button( onClick = { snackbarVisibilityState.value = !snackbarVisibilityState.value } ) { if (snackbarVisibilityState.value) { Text("隐藏 Snackbar") } else { Text("显示 Snackbar") } } if (snackbarVisibilityState.value) { Snackbar( action = { Button(onClick = {}) { Text(text = "MyAction") } }, modifier = Modifier.padding(10.dp) ) { Text("This is a snackbar!") } } } }
|