Dmitry Strekha
08/24/2021, 8:29 AMandroid:textColor
, android:textColorPrimary
and android:textColorSecondary
(plus some inverted versions) attributes.
In compose (and in Material in general) there are no special colors for text, but just colorOnX
.
I see a few solutions here:
- create a custom theme which extends Material theme and add colorText
and colorTextSecondary
(plus versions for onPrimary
).
- override LocalContentColor
with primary text color and apply alpha to it when need a secondary version. Not sure if this may work, because the result color may not be the same as desired color.
What is the best solution?Zoltan Demant
08/24/2021, 9:37 AMDmitry Strekha
08/24/2021, 1:19 PMif (isLight) lightColor else darkColor
in your Text composable? Does it scale to other themes beside liht/dark?Zoltan Demant
08/24/2021, 1:26 PMChris Sinco [G]
08/24/2021, 7:23 PMIn compose (and in Material in general) there are no special colors for text, but justYes that is intentional in the system. There are contentColors for text and icons, which is resolved with.colorOnX
contentColorFor
, which will look into the theme CompositionLocal context to find the right colorsChris Sinco [G]
08/24/2021, 7:23 PMChris Sinco [G]
08/24/2021, 7:25 PMCompositionLocalProvider
CompositionLocalProvider(LocalContentColor provides Color.White) {
Row(
verticalAlignment = Alignment.CenterVertically,
) {
IconButton(onClick = { onDismiss() }) {
Icon(
imageVector = Icons.Default.Close,
contentDescription = "Close action"
)
}
Text(
title,
style = MaterialTheme.typography.h3
)
}
IconButton(onClick = { }) {
Icon(
imageVector = Icons.Default.HelpOutline,
contentDescription = "Help action"
)
}
}
Chris Sinco [G]
08/24/2021, 7:28 PMChris Sinco [G]
08/24/2021, 7:29 PMDmitry Strekha
08/25/2021, 6:46 AM