I'm writing a small app and I see a problem with Material3 Text color element in dark mode. I've tried to minimize the app as possible to reproduce it and I've project that reproduces the problem on github. The entire application kotlin code is in the MainActivity.kt file. Material theme used in the project is defined in Theme.kt file. There are specially various colors to make the issue more visible.
In the main activity there are several Text elements that belong to a Surface and are displayed only when infoDisplayed state variable is set to true. After the app is started and lower info button is pressed the text elements become visible. The text color should be blue as onPrimaryContainer color is defined for dark mode but it's not! For one of the texts element there is even direct declaration that the color should be blue as presented below:
Text(
style = MaterialTheme.typography.bodyMedium,
text = "A selection of ...",
color = Color.Blue
)
And even this text doesn't have blue color.
However, when the app is open with those text displayed and then:
Few more information:
Any hint what did I wrote incorrectly or maybe if it's bug in Android's compose? Any workarounds? If it's a problem with compose should it be reported somewhere?
Ok, so the reason why those text have strange color are the "More dark options" as described in @Kartik answer to the question: Weird bug color text in dark mode compose
When I disable those options for my application then colors behave as expected.
Update that it also worked programmatically
It also works when I in code used both: the <item name="android:forceDarkAllowed" tools:targetApi="q">false</item>
and the
if(Build.VERSION.SDK_INT >= 29) {
LocalView.current.isForceDarkAllowed = false
}
in theme.kt file.