Switch
Android
Component in Jetpack Glance
Adds a switch view to the glance view.
Last updated:
Installation
dependencies {
implementation("androidx.glance:glance-appwidget:1.1.1")
}
Overloads
@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 ofchecked 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 bepassed 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 amutable PendingIntent ([android.app.PendingIntent.FLAG_MUTABLE]) when this action is not alambda. 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 ifnecessary. If the text exceeds the given number of lines, it will be truncated. |
@Composable
fun Switch(
checked: Boolean,
onCheckedChange: () -> Unit,
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 |
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 ifnecessary. If the text exceeds the given number of lines, it will be truncated. |
@ExperimentalGlanceApi
@Composable
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,
)
Parameters
name | description |
---|---|
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 ifnecessary. 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 ensuresthat the correct action is triggered, especially in cases of items that change order. If notprovided we use the key that is automatically generated by the Compose runtime, which is uniquefor every exact code location in the composition tree. |