Scaffold

박채빈·2024년 1월 24일
0

AndroidStudy

목록 보기
6/19
post-thumbnail

Scaffold

  • SlotAPI 확장

Default

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun ScaffoldEx() {
  var checked by remember { mutableStateOf(false) }

  Scaffold(
    topBar = {},
  ) {
    Surface(
      modifier = Modifier
        .fillMaxSize()
        .padding(it)
    ) {

    }
  }
}

TopAppBar, Content 추가

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun ScaffoldEx() {
  var checked by remember { mutableStateOf(false) }

  Scaffold(
    topBar = {
      TopAppBar(
        title = {
          Text(text = "Scaffold App")
        },
        navigationIcon = {
          IconButton(onClick = {}) {
            Icon(imageVector = Icons.Filled.ArrowBack, contentDescription = "")
          }
        }
      )
    },
    floatingActionButton = { // floating button
      FloatingActionButton(onClick = {}) {
        
      }
    }
  ) {
    Surface(
      modifier = Modifier.padding(it) // 이거 없으면 오류남
    ) {
      CheckBoxWithContent(
        checked = checked,
        toggleState = { checked = !checked }
      ) {
        Text(text = "Text1")
      }
    }
  }
}

@Composable
fun CheckBoxWithContent(
  checked: Boolean,
  toggleState: () -> Unit,
  content: @Composable RowScope.() -> Unit
) {
  Row(
    verticalAlignment = Alignment.CenterVertically,
    modifier = Modifier.clickable { toggleState() }
  ) {
    Checkbox(checked = checked, onCheckedChange = { toggleState() })
    content()
  }
}
profile
안드로이드 개발자

0개의 댓글