How do I change the onPress colour for a `TextButt...
# compose
p
How do I change the onPress colour for a
TextButton
? In my image the left one gets a dark grey colour when pressed. I would like to change it so something arbitrary, like say red.
l
This is configured within RippleTheme, so you could provide a custom ripple theme around the button
p
It worked thanks. Any plans to support it via parameter to Button component? Also in case someone else has the same question here is the code:
Copy code
CompositionLocalProvider(LocalRippleTheme provides object : RippleTheme {
    @Composable
    override fun defaultColor(): Color {
        return RippleTheme.defaultRippleColor(Color.Red, true)
    }

    @Composable
    override fun rippleAlpha(): RippleAlpha {
        return RippleAlpha(0f, 0f, 0f, 255f)
    }
}) {
    //Your button here
}
l
No, it's a core part of the Material theming system and shouldn't really be changed in this specific way - this is diverging from Material in some ways I guess
The contentColor inside ButtonColors is used for ripple color by default, but also the text / icons, it's supposed to match the content
p
Hm for me it always seems to be the same greyish color desipte setting the contentColor to something else for
TextButton
is there an other color i need to set aswell? In case i want to follow the Material standard
y
Copy code
InteractionSource.collectIsPressedAsState()
using above func you can observe button state change ...
Copy code
val isPressed by collectIsPressedAsState()
after that you can update colors based on state the
Copy code
ButtonDefaults.buttonColors(///)
l
Have you also set a custom ripple theme? If not, in dark theme it defaults to white in some cases for proper contrast
y
Yes