Button
Composable Function
Android
@Composable
fun Button(
text: String,
onClick: Action,
modifier: GlanceModifier = GlanceModifier,
enabled: Boolean = true,
style: TextStyle? = null,
colors: ButtonColors = ButtonDefaults.buttonColors(),
maxLines: Int = Int.MAX_VALUE,
) = ButtonElement(text, onClick, modifier, enabled, style, colors, maxLines)
Adds a button view to the glance view.
Parameters
text | The text that this button will show. |
onClick | The action to be performed when this button is clicked. |
modifier | The modifier to be applied to this button. |
enabled | If false, the button will not be clickable. |
style | The style to be applied to the text in this button. |
colors | The colors to use for the background and content of the button. |
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
fun Button(
text: String,
onClick: () -> Unit,
modifier: GlanceModifier = GlanceModifier,
enabled: Boolean = true,
style: TextStyle? = null,
colors: ButtonColors = ButtonDefaults.buttonColors(),
maxLines: Int = Int.MAX_VALUE,
) = ButtonElement(text, action(block = onClick), modifier, enabled, style, colors, maxLines)
Adds a button view to the glance view.
Parameters
text | The text that this button will show. |
onClick | The action to be performed when this button is clicked. |
modifier | The modifier to be applied to this button. |
enabled | If false, the button will not be clickable. |
style | The style to be applied to the text in this button. |
colors | The colors to use for the background and content of the button. |
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
fun Button(
text: String,
onClick: () -> Unit,
modifier: GlanceModifier = GlanceModifier,
enabled: Boolean = true,
style: TextStyle? = null,
colors: ButtonColors = ButtonDefaults.buttonColors(),
maxLines: Int = Int.MAX_VALUE,
key: String? = null
) = ButtonElement(text, action(key, onClick), modifier, enabled, style, colors, maxLines)
Adds a button view to the glance view.
Parameters
text | The text that this button will show. |
onClick | The action to be performed when this button is clicked. |
modifier | The modifier to be applied to this button. |
enabled | If false, the button will not be clickable. |
style | The style to be applied to the text in this button. |
colors | The colors to use for the background and content of the button. |
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 button. 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. |