BottomAppBar

박채빈·2024년 1월 25일
0

AndroidStudy

목록 보기
15/19
post-thumbnail
@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 적용
profile
안드로이드 개발자

0개의 댓글