Build apps faster with our new App builder! Check it out →

RadioButton

Android

Component in Jetpack Glance

Adds a radio button to the glance view.

When showing a [Row] or [Column] that has [RadioButton] children, use [GlanceModifier.selectableGroup] to enable the radio group effect (unselecting the previously selected radio button when another is selected).

Last updated:

Installation

dependencies {
   implementation("androidx.glance:glance-appwidget:1.1.1")
}

Overloads

@Composable
fun RadioButton(
    checked: Boolean,
    onClick: Action?,
    modifier: GlanceModifier = GlanceModifier,
    enabled: Boolean = true,
    text: String = "",
    style: TextStyle? = null,
    colors: RadioButtonColors = RadioButtonDefaults.colors(),
    maxLines: Int = Int.MAX_VALUE,
)

Parameters

namedescription
checkedwhether the radio button is checked
onClickthe action to be run when the radio button is clicked
modifierthe modifier to apply to the radio button
enabledif false, the radio button will not be clickable
textthe text to display to the end of the radio button
stylethe style to apply to [text]
colorsthe color tint to apply to the radio button
maxLinesAn 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 RadioButton(
    checked: Boolean,
    onClick: () -> Unit,
    modifier: GlanceModifier = GlanceModifier,
    enabled: Boolean = true,
    text: String = "",
    style: TextStyle? = null,
    colors: RadioButtonColors = RadioButtonDefaults.colors(),
    maxLines: Int = Int.MAX_VALUE,
)

Parameters

namedescription
checkedwhether the radio button is checked
onClickthe action to be run when the radio button is clicked
modifierthe modifier to apply to the radio button
enabledif false, the radio button will not be clickable
textthe text to display to the end of the radio button
stylethe style to apply to [text]
colorsthe color tint to apply to the radio button
maxLinesAn 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 RadioButton(
    checked: Boolean,
    onClick: () -> Unit,
    modifier: GlanceModifier = GlanceModifier,
    enabled: Boolean = true,
    text: String = "",
    style: TextStyle? = null,
    colors: RadioButtonColors = RadioButtonDefaults.colors(),
    maxLines: Int = Int.MAX_VALUE,
    key: String? = null,
)

Parameters

namedescription
checkedwhether the radio button is checked
onClickthe action to be run when the radio button is clicked
modifierthe modifier to apply to the radio button
enabledif false, the radio button will not be clickable
textthe text to display to the end of the radio button
stylethe style to apply to [text]
colorsthe color tint to apply to the radio button
maxLinesAn 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.
keyA stable and unique key that identifies the action for this radio button. 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.
by @alexstyl