Switch
Switches toggle the state of a single item on or off.
Parameters
whether or not this switch is checked.
called when this switch is clicked. If null, then this switch is not interactable, unless something else handles its input events and updates its state.
the Modifier to be applied to this switch.
controls the enabled state of this switch. When false, this component does not respond to user input, and it appears visually disabled to accessibility services.
SwitchColors that will be used to resolve the colors used for this switch in different states. See SwitchDefaults.switchColors.
the MutableInteractionSource representing the stream of Interactions for this switch. You can create and pass in your own remembered instance to observe Interactions and customize the appearance / behavior of this switch in different states.
Samples
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
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 androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.pico.spatial.ui.design.Switch
import com.pico.spatial.ui.design.Text
fun main() {
//sampleStart
var checked by remember { mutableStateOf(true) }
Switch(
modifier = Modifier.semantics { contentDescription = "Demo" },
checked = checked,
onCheckedChange = { checked = it },
)
//sampleEnd
}Switches toggle the state of a single item on or off.
Parameters
whether or not this switch is checked.
called when this switch is clicked. If null, then this switch is not interactable, unless something else handles its input events and updates its state.
the Modifier to be applied to this switch.
controls the enabled state of this switch. When false, this component does not respond to user input, and it appears visually disabled to accessibility services.
SwitchColors that will be used to resolve the colors used for this switch in different states. See SwitchDefaults.switchColors.
SwitchVibrants that will be used to resolve the vibrants used for this switch in different states. See SwitchDefaults.switchVibrants.
the MutableInteractionSource representing the stream of Interactions for this switch. You can create and pass in your own remembered instance to observe Interactions and customize the appearance / behavior of this switch in different states.
Samples
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
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 androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.pico.spatial.ui.design.Switch
import com.pico.spatial.ui.design.Text
fun main() {
//sampleStart
var checked by remember { mutableStateOf(true) }
Switch(
modifier = Modifier.semantics { contentDescription = "Demo" },
checked = checked,
onCheckedChange = { checked = it },
)
//sampleEnd
}