@Composable
fun BottomAppBarEx() {
val snackBarHostState = remember { SnackbarHostState() }
var counter by remember { mutableIntStateOf(0) }
val scope = rememberCoroutineScope()
Scaffold(
content = { innerPadding ->
Box(modifier = Modifier
.fillMaxSize()
.padding(innerPadding)) {
Text(text = "Counter: $counter", modifier = Modifier.align(Alignment.Center))
}
},
snackbarHost = { SnackbarHost(snackBarHostState) },
bottomBar = {
BottomAppBar {
Text("안녕하세요")
Button(onClick = {
scope.launch {
snackBarHostState.showSnackbar(
message = "Hello",
duration = SnackbarDuration.Short,
actionLabel = "Close"
)
}
}) {
Text("Hello")
}
Button(onClick = {
counter++
scope.launch {
snackBarHostState.showSnackbar(
message = "Counter: $counter",
duration = SnackbarDuration.Short,
actionLabel = "Close"
)
}
}) {
Text("Add")
}
Button(onClick = {
counter--
scope.launch {
snackBarHostState.showSnackbar(
message = "Counter: $counter",
duration = SnackbarDuration.Short,
actionLabel = "Close"
)
}
}) {
Text("Sub")
}
}
}
)
}
- Snackbar 적용