Compose Playground

Switch

A two-state toggle button.

Properties
Preview
Generated Code
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Switch
import androidx.compose.material3.Text
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp

@Composable
fun MySwitch() {
    var isChecked by remember { mutableStateOf(false) }

    Row(verticalAlignment = Alignment.CenterVertically) {
        Switch(
            checked = isChecked,
            onCheckedChange = { isChecked = it },
            enabled = true
        )
        Text(
            text = "Dark Mode",
            modifier = Modifier.padding(start = 8.dp)
        )
    }
}