← Back to Glance AppWidget
Switch
Overview
Code Examples
Video
Adds a switch view to the glance view.
@param checked whether the switch is checked @param onCheckedChange the action to be run when the switch is clicked. The current value of checked is provided to this action in its ActionParameters, and can be retrieved using the ToggleableStateKey. If this action launches an activity, the current value of checked will be passed as an intent extra with the name RemoteViews.EXTRA_CHECKED. @param modifier the modifier to apply to the switch @param text the text to display to the end of the switch @param style the style to apply to text @param colors the tint colors for the thumb and track of the switch @param maxLines An optional maximum number of lines for the text to span, wrapping if necessary. If the text exceeds the given number of lines, it will be truncated.
Overloads
Switch
@Composable
fun Switch(
checked: Boolean,
onCheckedChange: Action?,
modifier: GlanceModifier = GlanceModifier,
text: String = "",
style: TextStyle? = null,
colors: SwitchColors = SwitchDefaults.colors,
maxLines: Int = Int.MAX_VALUE,
)
Parameters
Name | Description |
---|---|
checked | whether the switch is checked |
onCheckedChange | the action to be run when the switch is clicked. The current value of checked is provided to this action in its ActionParameters, and can be retrieved using the ToggleableStateKey. If this action launches an activity, the current value of checked will be passed as an intent extra with the name RemoteViews.EXTRA_CHECKED. |
modifier | the modifier to apply to the switch |
text | the text to display to the end of the switch |
style | the style to apply to text |
colors | the tint colors for the thumb and track of the switch |
maxLines | An optional maximum number of lines for the text to span, wrapping if necessary. If the text exceeds the given number of lines, it will be truncated |