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)
}

Parameters

checked

Whether the checkbox is checked.

modifier

Modifier to be applied to the checkbox.

backgroundColor

Background color of the checkbox.

contentColor

Color of the content inside the checkbox.

enabled

Whether the checkbox is enabled.

onCheckedChange

Callback when the checked state changes.

shape

Shape of the checkbox.

borderColor

Color of the border.

borderWidth

Width of the border.

interactionSource

The interaction source for the checkbox.

indication

The indication to be shown when the checkbox is interacted with.

contentDescription

Accessibility description of the checkbox.

checkIcon

Composable function to define the check icon.