Compose Unstyled 2.0 is out! Check the official announcement blog ->

Binary switches for immediate on and off settings.

Use switches for settings that change state immediately.

View on GitHub
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import com.composables.ui.components.Switch
import com.composables.ui.components.Text

@Composable
fun SwitchExample() {
    var checked by remember { mutableStateOf(true) }
    Switch(checked = checked, onCheckedChange = { checked = it }) {
        Text("Notifications")
    }
}

Installation

implementation("com.composables:ui:0.1.0")

Examples

Disabled

View on GitHub
import androidx.compose.runtime.Composable
import com.composables.ui.components.Switch
import com.composables.ui.components.Text

@Composable
fun DisabledSwitchExample() {
    Switch(checked = true, onCheckedChange = {}, enabled = false) {
        Text("Notifications")
    }
}

API Reference

Switch

A binary switch for settings that change immediately.

@Composable
fun Switch(
    checked: Boolean,
    onCheckedChange: (Boolean) -> Unit,
    modifier: Modifier = Modifier,
    enabled: Boolean = true,
    accessibilityLabel: String? = null,
    interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
    content: (@Composable RowScope.() -> Unit)? = null,
)
Parameter Type Description
checked Boolean Whether the switch is currently on.
onCheckedChange (Boolean) -> Unit Called when the checked state changes.
modifier Modifier Modifier applied to the switch row.
enabled Boolean Whether the switch can be interacted with.
accessibilityLabel String?
interactionSource MutableInteractionSource Interaction source used for focus and press state.
content (@Composable RowScope.() -> Unit)? Optional label or supporting content displayed next to the switch.