Hi All! I've been given a design to implement in C...
# compose
n
Hi All! I've been given a design to implement in Compose that has a primary colour that doesn't contrast much with the desired surface colour and background colour. So, TextButton content ends up nearly invisible since the primary colour is chosen as the default content colour for the text. I could make text buttons use the secondary colour like this:
Copy code
TextButton(
                colors = textButtonColors(contentColor = MaterialTheme.colors.secondary),
                onClick = {
                }
            ) {
                Text("To Step 2")
            }
But I'd like to have something like this globally. Is there a way to provide the correct colour in my theme?
l
If you want all `TextButton`s to use secondary, then why not create something like:
Copy code
@Composable
fun MyTextButton(...) {
    TextButton(colors = textButtonColors(contentColor MaterialTheme.colors.secondary, ...)
}
n
That had occurred to me, but I wondered if there was a different way to approach it. I suppose, for now, that's the easiest. Thanks, @Louis Pullen-Freilich [G]
l
This is probably the most semantically meaningful, since a
TextButton
by definition uses
primary
🙂
n
Okay, this is what I ended up writing. Now even the name alludes to the default for the color.
l
Yep, exactly - so the call sites are semantically meaningful. You can also consider just not exposing parameters you don't want to customize, no need to duplicate the whole API surface if you never customize some of these 🙂
👍 2
c
I had to do this recently and I just created a new theme with the primary color set to my secondary color and then wrapped the composable in my theme called SecondaryTheme. That way I can reuse it for other item (my design team basically has two colors that it has been using for buttons, two colors for tabs, etc) so the theme has been useful in that case but I wasn't aware of this approach. Thanks @Louis Pullen-Freilich [G]
blob think smart 1