@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")
}
}
}
)
}
![](https://velog.velcdn.com/images/parkchaebin/post/f4325120-e831-4a4d-a965-57f3fcbf61fb/image.png)
- Snackbar 적용
![](https://velog.velcdn.com/images/parkchaebin/post/da6efa61-73f2-4194-af62-88e5c938b3a7/image.png)