Jakub Ledwon
01/18/2021, 2:55 PMBryan Herbst
01/18/2021, 3:24 PMButton
internally uses AmbientIndication
, which by default is just rememberRipple()
.
If you want to change the color for a single button, you can wrap that button in with a new AmbientIndication
provider like so:
val customRippleFactory: @Composable() -> Indication = remember {
@Composable { rememberRipple(color = WhateverColorYouWant) }
}
Providers(AmbientIndication provides customRippleFactory) {
Button() {
// ...
}
}
If you want to customize the behavior for all your buttons, you probably want to do this at your theme level, and provide an AmbientRippleTheme
instead. MaterialTheme
ships with a MaterialRippleTheme
that you can use as a starting point for whatever behavior you wantJakub Ledwon
01/18/2021, 3:57 PMLouis Pullen-Freilich [G]
01/18/2021, 5:47 PMAmbientIndication
- it's used as a default for components like clickable
but it isnt' intended to be a way to override the ripple in Material components - it sounds like there is a more core issue here since the ripple color should work properly without you needing to override this.
What are the colors in your MaterialTheme
in light / dark theme, and what parameters are you passing to the Button
?Jakub Ledwon
01/18/2021, 5:51 PMprivate val DarkColorPalette = darkColors(
primary = purple200,
primaryVariant = purple700,
secondary = teal200
)
private val LightColorPalette = lightColors(
primary = purple500,
primaryVariant = purple700,
secondary = teal200
)
other colors are default.Louis Pullen-Freilich [G]
01/18/2021, 5:56 PMJakub Ledwon
01/18/2021, 6:01 PMButton(
colors = ButtonDefaults.buttonColors(backgroundColor = Color.White / Color.Black)
...
)
Andrey Kulikov
01/18/2021, 6:47 PMbuttonColors
function: contentColor
. this color will be applied for the both text of the button and rippleOussama Haff.
01/20/2021, 4:55 PMrippleColor
in the style of Widget.MaterialComponents.Button
Correct me if I’m wrong, now in Compose (alpha-10) there is now way to apply the ripple only on the background of the default Button. To do so, we need to create our own Button on top of the foundation composablesLouis Pullen-Freilich [G]
01/20/2021, 5:06 PMCorrect me if I’m wrong, now in Compose (alpha-10) there is now way to apply the ripple only on the background of the default ButtonSorry, not sure I follow - what is your use case here?
contentColor
is used for text / iconography / ripples, so if you want to change the ripple color you can just change the contentColor you pass to buttonColors
Oussama Haff.
01/20/2021, 5:35 PMIndication
the parameter buttonColors
accepts only Colors and not Indication.
I would be thankful if you can share a sample where the ripple color is customized through buttonColors
: )Louis Pullen-Freilich [G]
01/20/2021, 5:38 PMAs said by Bryan Herbst, to personalize the ripple color for a default Compose button we need to encapsulate the Button in a Composable that provides the ripple as Ambient which is of typeThis actually has just been removed and won't be supported in the next release of Compose - this was an internal implementation detail that isn't really an intended place for customization 🙂Indication
I would be thankful if you can share a sample where the ripple color is customized through: ) (edited)buttonColors
Button(
onClick = { },
colors = ButtonDefaults.buttonColors(contentColor = Color.Red)
) {
Text(text = "Hello")
}
In this example the text and the ripple will be redLouis Pullen-Freilich [G]
01/20/2021, 5:39 PMRippleTheme
and change how the color for ripple is calculatedBryan Herbst
01/20/2021, 5:49 PMRippleTheme
is sticking around- I think that will be a better entry point for customizing ripple colors for cases where you don’t want the text color and ripple color to be the same as with contentColor
Bryan Herbst
01/20/2021, 5:53 PM@Composable
fun CustomTheme(content: @Composable () -> Unit) {
Providers(AmbientRippleTheme provides customRippleTheme) {
content()
}
}
Louis Pullen-Freilich [G]
01/20/2021, 5:55 PM