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

ursus

10/14/2023, 2:18 PM
How does button get ripple color based on it's contents? When using
Card
I always get the gray one I don't want to change it globally to a certain color, but do what button does, i.e. tint the ripple based on content color automatically
c

cah

10/14/2023, 3:14 PM
Off the top of my head you can provide an indication to clickable or potentially replace the one provided by composition local within your card
l

Louis Pullen-Freilich [G]

10/14/2023, 3:34 PM
It uses the content color provided above it / through a content color parameter, so make sure you are also setting content color
2
s

Stylianos Gakis

10/16/2023, 1:54 PM
make sure you are also setting content color
Which the
Surface
composable does for you if you look inside of it, which is why it’s convenient to use for many cases.
u

ursus

10/17/2023, 5:45 PM
but setting the
contentColor
obviously colors the content texts inside it .. I don't want that, this is what I'm after
so .. black text all the time, just blue ripple can I only change the ripple color without the content color? i.e. to not have ripple be function of the contnet color?
s

Stylianos Gakis

10/17/2023, 5:47 PM
So, another contentColor needed inside the content, under the place where the ripple is already set to blue perhaps?
u

ursus

10/17/2023, 5:48 PM
not sure what you mean .. basically I want a blue ripple, all the time, on this sort of Card component..lets call it SelectableCard
l

Louis Pullen-Freilich [G]

10/17/2023, 5:48 PM
Yeah, just set content color for the ripple to blue, and then for the text area, provide a different content color
s

Stylianos Gakis

10/17/2023, 5:48 PM
Surface(blue) { Card(clickable) { Surface(normal color) { (or just set the composition local itself) Text Something like this?
u

ursus

10/17/2023, 5:49 PM
hmm, but I need the contents to be generic ..so you're saying I should put another Surface inside just to override "back" the overriden contentColor?
Copy code
fun SelectableCard(
    modifier: Modifier = Modifier,
    selected: Boolean,
    onClick: () -> Unit,
    content: @Composable () -> Unit
) {
this is interface I had in mind
s

Stylianos Gakis

10/17/2023, 5:53 PM
You can make this work. You can initially take the existing localcontentcolor and save the val, then provide the blue color in a surface, and inside the lambda of that surface (after the clickable is set) provide the local content color again which you had saved only to the content. Does that make sense? I can write a little snippet if not.
u

ursus

10/17/2023, 5:54 PM
by provide you mean
Copy code
CompositionLocalProvider(
            LocalContentColor provides MaterialTheme.colors.onPrimary
        ) {
this?
👍 1