跳转至

Switch

属性

@Composable
fun Switch(
    checked: Boolean?,
    onCheckedChange: ((Boolean) -> Unit)?,
    modifier: Modifier? = Modifier,
    enabled: Boolean? = true,
    interactionSource: MutableInteractionSource? = remember { MutableInteractionSource() },
    colors: SwitchColors? = SwitchDefaults.colors()
): Unit

用法

@Composable
fun SwitchSample() {
    //声明一个变量来记住选中状态
    var switch by remember { mutableStateOf(false) }
    Switch(checked = switch, onCheckedChange = {
        //当进行切换操作时,更改状态
        switch = it
    })
}

switch

更多

Switch

视频教程

https://www.bilibili.com/video/BV1N44y1n7TR

实战视频