I created to kt files MainActivity.kt and MainPage.kt, I pu my own colors in color.ket and refeerenced them in theme.kt
Omposables in MainActivity.kt get the right colors but MainPage.kt do not
I have a card in MainPage.kt:
Card(
colors = CardDefaults.cardColors(
containerColor = MaterialTheme.colorScheme.onPrimary
),
modifier = Modifier
.clip(cardShape)
.height(200.dp)
.width(cardWidth)
.border(
width = 3.dp,
color = MaterialTheme.colorScheme.secondaryContainer,
shape = cardShape
)
) {
Column(modifier = Modifier.padding(start = 15.dp, top=10.dp)) {
Text(text = "Info Card bottom")
}
}
MaterialTheme.colorScheme.onPrimary (material3) should be greenish, but it gives me light purple.
Any ideas, plesae?
*** I am learning making android app and I probably just dd something wrong.
I deleted the original purple colors in color.kt so I do not know where that color comes from. I also pur dynamicColor to false in theme.kt
May be helpful:
Sometimes all you need is to set: dynamicColor: Boolean = false, in your AppTheme Composable in Theme.kt.
Try removing(or commenting) the following code snippet from the colorScheme in your Theme.kt file.
dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
val context = LocalContext.current
if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
}
It should be like:
val colorScheme = when {
darkTheme -> darkColorScheme
else -> lightColorScheme
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With