Android(kotlin) - JetPack Compose - BottomAppBar (Material3)

하동혁 ·2023년 9월 1일
0

Android Jetpack Compose

목록 보기
28/30
post-thumbnail

BottomAppBar

@Composable
fun BottomAppBarEx() {
    val snackbarHostState = remember { SnackbarHostState() }
    val scope = rememberCoroutineScope()

    var counter by remember {
        mutableStateOf(0)
    }

    Scaffold (
        snackbarHost = { SnackbarHost(snackbarHostState) },

        bottomBar = {
            BottomAppBar() {
                Text("study")
                Button(onClick = {
                    scope.launch {
                        snackbarHostState.showSnackbar( // 스낵바 결과 받기 가능
                            message = "snackBar 보인다~~!!",
                            actionLabel = "close",
                            duration = SnackbarDuration.Short
                        )
                    }
                }) {
                    Text("show SnackBar")
                }
                Button(onClick = {
                    counter++
                }) {
                    Text(text = "+")
                }
                Button(onClick = {
                    counter--
                }) {
                    Text(text = "-")
                }
            }
        }
    ) {
				Surface(
            modifier = Modifier.padding(it),
        ) {
            Text(text = " ")
        }
    }
}

@Preview(showBackground = true)
@Composable
fun BottomAppBarPreview() {
    Compose_exampleTheme {
        BottomAppBarEx()
    }
}

0개의 댓글