Reputation: 7352
This seems to exist in most UI frameworks, in a way that will work with both light and dark themes, but it seems to be absent here.
Currently I've resorted to doing:
val Muted = Color.LightGray
and importing that elsewhere, but it looks bad on light themes.
Any ideas?
Upvotes: 0
Views: 1142
Reputation: 504
Compose has ContentAlpha.medium
, that is used, as the name suggests, to display a color as muted.
I don't know if this is the most efficient way to do it, but I usually use it like this:
Text(
text = myText,
color = when {
isEnabled -> MaterialTheme.colors.myColor
else -> MaterialTheme.colors.myColor.copy(alpha = ContentAlpha.medium)
}
)
You could abstract it into a extension field and add it to your themes file:
val Color.muted get() = this.copy(alpha = ContentAlpha.medium)
And use it like this:
color = when {
isEnabled -> MaterialTheme.colors.myColor
else -> MaterialTheme.colors.myColor.muted
Upvotes: 2
Reputation: 214
Using Color.luminance()
value of the background color and choose the Grayscale color of the text in case of dynamic theming.
Using isSystemInDarkTheme()
to pick color in combination with contentColorFor()
, when we have fixed theming system,
Upvotes: 0