← Back to Wear Material Core
Switch
Overview
Code Examples
Switch provides an animated switch for use in material APIs.
@param modifier Modifier to be applied to the switch. This can be used to provide a content description for accessibility. @param checked Boolean flag indicating whether this switch is currently toggled on. @param enabled Boolean flag indicating the enabled state of the Switch (affects the color). @param onCheckedChange Callback to be invoked when Switch is clicked. If null, then this is passive and relies entirely on a higher-level component to control the state. @param interactionSource When also providing onCheckedChange, the MutableInteractionSource representing the stream of Interactions for the "toggleable" tap area - can be used to customise the appearance / behavior of the Switch. @param trackFillColor Composable lambda from which the fill color of the track will be obtained. @param trackStrokeColor Composable lambda from which the stroke color of the track will be obtained. @param thumbColor Composable lambda from which the thumb color will be obtained. @param thumbIconColor Composable lambda from which the icon color will be obtained. @param trackWidth Width of the track. @param trackHeight Height of the track. @param drawThumb Lambda function to draw the thumb of the switch. The lambda is invoked with trackFillColor as the icon color, along with the thumbColor, and the progress. @param progressAnimationSpec Animation spec to animate the progress. @param width Width of the switch. @param height Height of the switch.
Overloads
Switch
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
@Composable
fun Switch(
modifier: Modifier,
checked: Boolean,
enabled: Boolean,
onCheckedChange: ((Boolean) -> Unit)?,
interactionSource: MutableInteractionSource,
trackFillColor: @Composable (enabled: Boolean, checked: Boolean) -> State<Color>,
trackStrokeColor: @Composable (enabled: Boolean, checked: Boolean) -> State<Color>,
thumbColor: @Composable (enabled: Boolean, checked: Boolean) -> State<Color>,
thumbIconColor: @Composable (enabled: Boolean, checked: Boolean) -> State<Color>,
trackWidth: Dp,
trackHeight: Dp,
drawThumb: FunctionDrawThumb,
progressAnimationSpec: TweenSpec<Float>,
width: Dp,
height: Dp,
)
Parameters
Name | Description |
---|---|
modifier | Modifier to be applied to the switch. This can be used to provide a content description for accessibility. |
checked | Boolean flag indicating whether this switch is currently toggled on. |
enabled | Boolean flag indicating the enabled state of the Switch (affects the color). |
onCheckedChange | Callback to be invoked when Switch is clicked. If null, then this is passive and relies entirely on a higher-level component to control the state. |
interactionSource | When also providing onCheckedChange, the MutableInteractionSource representing the stream of Interactions for the "toggleable" tap area - can be used to customise the appearance / behavior of the Switch. |
trackFillColor | Composable lambda from which the fill color of the track will be obtained. |
trackStrokeColor | Composable lambda from which the stroke color of the track will be obtained. |
thumbColor | Composable lambda from which the thumb color will be obtained. |
thumbIconColor | Composable lambda from which the icon color will be obtained. |
trackWidth | Width of the track. |
trackHeight | Height of the track. |
drawThumb | Lambda function to draw the thumb of the switch. The lambda is invoked with trackFillColor as the icon color, along with the thumbColor, and the progress. |
progressAnimationSpec | Animation spec to animate the progress. |
width | Width of the switch. |
height | Height of the switch |