https://kotlinlang.org logo
#compose
Title
# compose
c

Colton Idle

01/03/2022, 9:53 PM
Is there a way to have a Material Button with a gradient? I found this sample which works until I try to apply a CircleShape to it so that it becomes a "pill" shaped button. https://stackoverflow.com/questions/65542068/jetpack-compose-button-with-gradient-background Is there no way to define a single color as a gradient?
c

curioustechizen

01/04/2022, 7:07 AM
AFAIK the material spec does not mention gradients for buttons so Compose material library Buttons don't support it. However the JetSnack sample has an example of implementing a custom Button with gradients
1
c

Chris Sinco [G]

01/04/2022, 7:38 AM
Yeah trying to use modifiers to add the gradient won't work well due to the layering within the Button implementation in how it's using Surface and passing color parameters down through the tree. It would be easier ATM to just reimplement Button which is essentially what Jetsnack does - that is, it sets the inner Surface color to unspecified, and instead uses a gradient background color modifier.
And yes, Material spec doesn't have gradient buttons, even in Material3, so there hasn't been a request yet to make Material Button flexible for gradients. But it doesn't hurt to file a request. 🙂
c

Colton Idle

01/04/2022, 2:54 PM
Will file! Thanks for the link to jetsnack. that sounds like exactly what I need!
👍 1
37 Views