Checkbox
fun Checkbox(checked: Boolean, modifier: Modifier = Modifier, backgroundColor: Color = Color.Transparent, contentColor: Color = LocalContentColor.current, enabled: Boolean = true, onCheckedChange: (Boolean) -> Unit? = null, shape: Shape = RectangleShape, borderColor: Color = Color.Unspecified, borderWidth: Dp = 1.dp, interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, indication: Indication? = LocalIndication.current, contentDescription: String? = null, checkIcon: @Composable () -> Unit)
A foundational component used to build checkboxes.
For interactive preview & code examples, visit Checkbox Documentation.
Basic Example
var checked by remember { mutableStateOf(false) }
Checkbox(
checked = checked,
onCheckedChange = { checked = it },
shape = RoundedCornerShape(4.dp),
backgroundColor = Color.White,
contentColor = Color.Black
) {
// will be shown if checked
Icon(Check, contentDescription = null)
}Content copied to clipboard
Parameters
checked
Whether the checkbox is checked.
modifier
Modifier to be applied to the checkbox.
background Color
Background color of the checkbox.
content Color
Color of the content inside the checkbox.
enabled
Whether the checkbox is enabled.
on Checked Change
Callback when the checked state changes.
shape
Shape of the checkbox.
border Color
Color of the border.
border Width
Width of the border.
interaction Source
The interaction source for the checkbox.
indication
The indication to be shown when the checkbox is interacted with.
content Description
Accessibility description of the checkbox.
check Icon
Composable function to define the check icon.