Guys, I have a questions about colors. I created a...
# compose
g
Guys, I have a questions about colors. I created a splash screen composable which is a constraintlayout with two Text() inside. Color of both of text components is setted to yellow. But when I get this screen on my app, both of them are blue. If I add backgroundColor to ConstraintLayout() it becomes also light blue. Anybody knows what is the problem? Maybe I need to add somewhere Surface()?
a
uhm, how are you adding the colors? do they come from MaterialTheme?
g
no, directly from colors.xml
it depends on it?
g
Can you provide the code, please
g
Copy code
@Composable
fun SplashScreen(){

    ConstraintLayout(
        modifier = Modifier.fillMaxSize()
    ) {
        val (appLogoRef, authorSignatureRef) = createRefs()

        Text(
            color = Color(R.color.splash_text_color),
            text = "App logo",
            style = TextStyle(
                fontWeight = FontWeight.W900,
                fontSize = 32.sp
            ),
            modifier = Modifier.constrainAs(appLogoRef){
                linkTo(
                    top = <http://parent.top|parent.top>,
                    bottom = parent.bottom,
                    start = parent.start,
                    end = parent.end
                )
            }
        )

        Text(
            color = Color(R.color.splash_text_color),
            text = "by author",
            style = TextStyle(
                fontWeight = FontWeight.W900,
                fontSize = 16.sp
            ),
            modifier = Modifier.constrainAs(authorSignatureRef){
                bottom.linkTo(parent.bottom, 16.dp)
                end.linkTo(parent.end, 16.dp)
            }
        )
    }
}
a
uhm, not sure coor works like this
you must add
colorResource
Copy code
Color(colorResource(id = R.color.purple_200))
g
Yeah, you are right! Thanks a lot.
g
I think we need Android studio warning for this case
a
it would be great @Grigorii Yurkov
g
Yes, definitely
a
btw, it would be better if you use MaterialTheme colors
g
I will. It was just an example screen for learning how constraintLayout works in compose
g
Do we even need to use
color.xml
in compose?
a
well, yes for the colors on the app ¯\_(ツ)_/¯
g
But we have
Colors.kt
for this purpose
a
not for app things that are not on compose
is needed for app theme, etc
g
Yes, this is exception. I didn't say "we don't need color.xml at all"
m
You can create your own compose themes by the way. It’s not terribly difficult, now that they fixed the source code jars, if you look at MaterialTheme you can get an idea how to do it.
A theme is really just a way of proving instances of Ambient values. A theme, in and of itself is a Composable function that just sets current ambient values.