체크박스를 사용하면 사용자가 목록에서 하나 이상의 항목을 선택할 수 있습니다. 체크박스를 사용하여 사용자가 다음 작업을 할 수 있도록 할 수 있습니다.
항목을 사용 설정 또는 사용 중지합니다.
목록에서 여러 옵션 중에서 선택합니다.
동의 또는 수락을 표시합니다.
분석
체크박스는 다음 요소로 구성됩니다.
상자: 체크박스의 컨테이너입니다.
체크: 체크박스가 선택되었는지 여부를 보여주는 시각적 표시기입니다.
라벨: 체크박스를 설명하는 텍스트입니다.
상태
체크박스는 다음 세 가지 상태 중 하나일 수 있습니다.
선택되지 않음: 체크박스가 선택되지 않았습니다. 상자가 비어 있습니다.
불확실: 체크박스가 불확실한 상태입니다. 상자에는 대시가 포함되어 있습니다.
선택됨: 체크박스가 선택되어 있습니다. 상자에는 체크표시가 포함되어 있습니다.
다음 이미지는 체크박스의 세 가지 상태를 보여줍니다.
그림 1. 체크박스의 세 가지 상태 선택 해제, 미결정, 선택됨
구현
Checkbox 컴포저블을 사용하여 앱에 체크박스를 만들 수 있습니다. 다음은 몇 가지 주요 매개변수입니다.
checked: 체크박스가 선택되었는지 선택 해제되었는지 여부를 캡처하는 불리언입니다.
onCheckedChange(): 사용자가 체크박스를 탭할 때 앱이 호출하는 함수입니다.
다음 스니펫은 Checkbox 컴포저블을 사용하는 방법을 보여줍니다.
@ComposablefunCheckboxMinimalExample(){varcheckedbyremember{mutableStateOf(true)}Row(verticalAlignment=Alignment.CenterVertically,){Text("Minimal checkbox")Checkbox(checked=checked,onCheckedChange={checked=it})}Text(if(checked)"Checkbox is checked"else"Checkbox is unchecked")}
이 코드는 처음에 선택되지 않은 체크박스를 만듭니다. 사용자가 체크박스를 클릭하면 onCheckedChange 람다가 checked 상태를 업데이트합니다.
결과
이 예시에서는 선택되지 않은 경우 다음 구성요소를 생성합니다.
그림 2. 선택 해제된 체크박스
체크박스를 선택하면 다음과 같이 표시됩니다.
그림 3. 선택된 체크박스
고급 예시
다음은 앱에서 체크박스를 구현하는 방법을 보여주는 더 복잡한 예입니다. 이 스니펫에는 상위 체크박스와 일련의 하위 체크박스가 있습니다. 사용자가 상위 체크박스를 탭하면 앱에서 모든 하위 체크박스를 선택합니다.
@ComposablefunCheckboxParentExample(){// Initialize states for the child checkboxesvalchildCheckedStates=remember{mutableStateListOf(false,false,false)}// Compute the parent state based on children's statesvalparentState=when{childCheckedStates.all{it}->ToggleableState.OnchildCheckedStates.none{it}->ToggleableState.Offelse->ToggleableState.Indeterminate}Column{// Parent TriStateCheckboxRow(verticalAlignment=Alignment.CenterVertically,){Text("Select all")TriStateCheckbox(state=parentState,onClick={// Determine new state based on current statevalnewState=parentState!=ToggleableState.OnchildCheckedStates.forEachIndexed{index,_->
childCheckedStates[index]=newState}})}// Child CheckboxeschildCheckedStates.forEachIndexed{index,checked->
Row(verticalAlignment=Alignment.CenterVertically,){Text("Option ${index+1}")Checkbox(checked=checked,onCheckedChange={isChecked->
// Update the individual child statechildCheckedStates[index]=isChecked})}}}if(childCheckedStates.all{it}){Text("All options selected")}}
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2025-08-28(UTC)
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["필요한 정보가 없음","missingTheInformationINeed","thumb-down"],["너무 복잡함/단계 수가 너무 많음","tooComplicatedTooManySteps","thumb-down"],["오래됨","outOfDate","thumb-down"],["번역 문제","translationIssue","thumb-down"],["샘플/코드 문제","samplesCodeIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-08-28(UTC)"],[],[],null,["Checkboxes let users select one or more items from a list. You might use a\ncheckbox to let the user do the following:\n\n- Turn an item on or off.\n- Select from multiple options in a list.\n- Indicate agreement or acceptance.\n\n| **Note:** Use checkboxes instead of [switches](/develop/ui/compose/components/switch) or [radio buttons](https://m3.material.io/components/radio-button) if the user can select multiple options in a list.\n\nAnatomy\n\nA checkbox consists of the following elements:\n\n- **Box**: This is the container for the checkbox.\n- **Check**: This is the visual indicator that shows whether the checkbox is selected or not.\n- **Label**: This is the text that describes the checkbox.\n\nStates\n\nA checkbox can be in one of three states:\n\n- **Unselected**: The checkbox is not selected. The box is empty.\n- **Indeterminate**: The checkbox is in an indeterminate state. The box contains a dash.\n- **Selected**: The checkbox is selected. The box contains a checkmark.\n\nThe following image demonstrates the three states of a checkbox.\n**Figure 1.** The three states of a checkbox. Unselected, indeterminate, and selected.\n\nImplementation\n\nYou can use the [`Checkbox`](/reference/kotlin/androidx/compose/material3/package-summary#Checkbox(kotlin.Boolean,kotlin.Function1,androidx.compose.ui.Modifier,kotlin.Boolean,androidx.compose.material3.CheckboxColors,androidx.compose.foundation.interaction.MutableInteractionSource)) composable to create a checkbox in your app.\nThere are just a few key parameters to keep in mind:\n\n- `checked`: The boolean that captures whether the checkbox is checked or unchecked.\n- `onCheckedChange()`: The function that the app calls when the user taps the checkbox.\n\nThe following snippet demonstrates how to use the `Checkbox` composable:\n\n\n```kotlin\n@Composable\nfun CheckboxMinimalExample() {\n var checked by remember { mutableStateOf(true) }\n\n Row(\n verticalAlignment = Alignment.CenterVertically,\n ) {\n Text(\n \"Minimal checkbox\"\n )\n Checkbox(\n checked = checked,\n onCheckedChange = { checked = it }\n )\n }\n\n Text(\n if (checked) \"Checkbox is checked\" else \"Checkbox is unchecked\"\n )\n}https://github.com/android/snippets/blob/7a0ebbee11495f628cf9d574f6b6069c2867232a/compose/snippets/src/main/java/com/example/compose/snippets/components/Checkbox.kt#L62-L81\n```\n\n\u003cbr /\u003e\n\nExplanation\n\nThis code creates a checkbox that is initially unchecked. When the user clicks\non the checkbox, the `onCheckedChange` lambda updates the `checked` state.\n\nResult\n\nThis example produces the following component when unchecked:\n**Figure 2.** Unchecked checkbox\n\nAnd this is how the same checkbox appears when checked:\n**Figure 3.** Checked checkbox\n\nAdvanced example\n\nThe following is a more complex example of how you can implement checkboxes in\nyour app. In this snippet, there is a parent checkbox and a series of child\ncheckboxes. When the user taps the parent checkbox, the app checks all child\ncheckboxes.\n\n\n```kotlin\n@Composable\nfun CheckboxParentExample() {\n // Initialize states for the child checkboxes\n val childCheckedStates = remember { mutableStateListOf(false, false, false) }\n\n // Compute the parent state based on children's states\n val parentState = when {\n childCheckedStates.all { it } -\u003e ToggleableState.On\n childCheckedStates.none { it } -\u003e ToggleableState.Off\n else -\u003e ToggleableState.Indeterminate\n }\n\n Column {\n // Parent TriStateCheckbox\n Row(\n verticalAlignment = Alignment.CenterVertically,\n ) {\n Text(\"Select all\")\n TriStateCheckbox(\n state = parentState,\n onClick = {\n // Determine new state based on current state\n val newState = parentState != ToggleableState.On\n childCheckedStates.forEachIndexed { index, _ -\u003e\n childCheckedStates[index] = newState\n }\n }\n )\n }\n\n // Child Checkboxes\n childCheckedStates.forEachIndexed { index, checked -\u003e\n Row(\n verticalAlignment = Alignment.CenterVertically,\n ) {\n Text(\"Option ${index + 1}\")\n Checkbox(\n checked = checked,\n onCheckedChange = { isChecked -\u003e\n // Update the individual child state\n childCheckedStates[index] = isChecked\n }\n )\n }\n }\n }\n\n if (childCheckedStates.all { it }) {\n Text(\"All options selected\")\n }\n}https://github.com/android/snippets/blob/7a0ebbee11495f628cf9d574f6b6069c2867232a/compose/snippets/src/main/java/com/example/compose/snippets/components/Checkbox.kt#L86-L136\n```\n\n\u003cbr /\u003e\n\nExplanation\n\nThe following are several points you should note from this example:\n\n- **State management** :\n - `childCheckedStates`: A list of booleans using `mutableStateOf()` to track the checked state of each child checkbox.\n - `parentState`: A [`ToggleableState`](/reference/kotlin/androidx/compose/ui/state/ToggleableState?_gl=1*1nllj9c*_up*MQ..*_ga*MTQ4MjE3NjI1Ny4xNzE1MzM1Nzc0*_ga_6HH9YJMN9M*MTcxNTMzNTc3NC4xLjAuMTcxNTMzNTc3NC4wLjAuMA..) whose value derives from the child checkboxes' states.\n- **UI components** :\n - [`TriStateCheckbox`](/reference/kotlin/androidx/compose/material3/package-summary#TriStateCheckbox(androidx.compose.ui.state.ToggleableState,kotlin.Function0,androidx.compose.ui.Modifier,kotlin.Boolean,androidx.compose.material3.CheckboxColors,androidx.compose.foundation.interaction.MutableInteractionSource)): Is necessary for the parent checkbox as it has a `state` param that lets you set it to indeterminate.\n - [`Checkbox`](/reference/kotlin/androidx/compose/material3/package-summary#Checkbox(kotlin.Boolean,kotlin.Function1,androidx.compose.ui.Modifier,kotlin.Boolean,androidx.compose.material3.CheckboxColors,androidx.compose.foundation.interaction.MutableInteractionSource)): Used for each child checkbox with its state linked to the corresponding element in `childCheckedStates`.\n - `Text`: Displays labels and messages (\"Select all\", \"Option X\", \"All options selected\").\n- **Logic** :\n - The parent checkbox's `onClick` updates all child checkboxes to the opposite of the current parent state.\n - Each child checkbox's `onCheckedChange` updates its corresponding state in the `childCheckedStates` list.\n - The code displays \"`All options selected`\" when all child checkboxes are checked.\n\n| **Note:** If you want to have a checkbox with an indeterminate state, you must use `TriStateCheckbox`. This is because it has a `state` parameter of type `ToggleableState`, whereas `Checkbox` does not.\n\nResult\n\nThis example produces the following component when all checkboxes are unchecked.\n**Figure 4.** Unchecked checkboxes\n\nLikewise, this is how the component appears when all options are checked, as\nwhen the user taps select all:\n**Figure 5.** Checked checkboxes\n\nWhen only one option is checked the parent checkbox display the indeterminate\nstate:\n**Figure 6.** Indeterminate checkbox\n\nAdditional resources\n\n- [Material Design Checkboxes](https://m3.material.io/components/checkbox/overview)"]]