State of Compose 2023 results are in! Click here to learn more

← Back to Glance AppWidget

Switch

Component
in
Glance AppWidget
. Since 1.0.0

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

NameDescription
checkedwhether the switch is checked
onCheckedChangethe 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.
modifierthe modifier to apply to the switch
textthe text to display to the end of the switch
stylethe style to apply to text
colorsthe tint colors for the thumb and track of the switch
maxLinesAn 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