Composable Function
Android
@Composable
public fun Switch(
    checked: Boolean,
    onCheckedChange: Action?,
    modifier: GlanceModifier = GlanceModifier,
    text: String = "",
    style: TextStyle? = null,
    colors: SwitchColors = SwitchDefaults.colors(),
    maxLines: Int = Int.MAX_VALUE,
): Unit

Adds a switch view to the glance view.

Parameters

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. In order to allow the Launcher to provide this extra on Android version S and later, we use a mutable PendingIntent (android.app.PendingIntent.FLAG_MUTABLE) when this action is not a lambda. Before S, and for lambda actions, this will be an immutable PendingIntent.
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.
Android
@Composable
public fun Switch(
    checked: Boolean,
    onCheckedChange: () -> Unit,
    modifier: GlanceModifier = GlanceModifier,
    text: String = "",
    style: TextStyle? = null,
    colors: SwitchColors = SwitchDefaults.colors(),
    maxLines: Int = Int.MAX_VALUE,
): Unit

Adds a switch view to the glance view.

Parameters

checked whether the switch is checked
onCheckedChange the action to be run when the switch is clicked
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.
Android
@ExperimentalGlanceApi
@Composable
public fun Switch(
    checked: Boolean,
    onCheckedChange: () -> Unit,
    modifier: GlanceModifier = GlanceModifier,
    text: String = "",
    style: TextStyle? = null,
    colors: SwitchColors = SwitchDefaults.colors(),
    maxLines: Int = Int.MAX_VALUE,
    key: String? = null,
): Unit

Adds a switch view to the glance view.

Parameters

checked whether the switch is checked
onCheckedChange the action to be run when the switch is clicked
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.
key A stable and unique key that identifies the action for this switch. This ensures that the correct action is triggered, especially in cases of items that change order. If not provided we use the key that is automatically generated by the Compose runtime, which is unique for every exact code location in the composition tree.