Hello all. I am having issues with text color and...
# compose
b
Hello all. I am having issues with text color and a dark surface. As far as I can tell, when using a dark surface the text color should be a light text color. However in this instance my text color is dark an unreadable. Code in reply
Copy code
Surface(color = Color.Black) {
   Text(text = "Hello World)
}
k
Assuming you are using M2 / M3 top-level theme. Composables such as
Text
take their colors from that theme. When you override the
Surface
color somewhere in your hierarchy, you can’t expect everything “under” that node to somehow automatically adjust to that off-theme color. You can set a dark-colors theme as a wrapper around your
Surface
- which would then make everything in that sub-tree adopt the dark appearance. Or if you do something custom like this, you’ll need to also be explicitly custom in every child - which is your
Text
Maybe what you expect comes from this blocks:
image.png
image.png
But unless your
Surface.color
is exactly one of the RGBs in this
when
block, you will get
Color.Unspecified
which will then fall back to the theme color for your
Text
And even if it’s the exact match, it will return one of the
onXYZ
colors from the theme, and not a dynamically generated value that is based on your black color for the surface.
b
Yes, that is what I was expecting, but didn’t dig far enough. Thank you!
Just saw the contentColorFor(…) and thought that was dynamically calculating the color