https://kotlinlang.org logo
#compose
Title
# compose
d

Daniele B

10/22/2020, 12:23 PM
There is something I don’t understand about Theming. I have defined my own typography:
Copy code
val typography = Typography(
    body1 = TextStyle(
        fontWeight = FontWeight.Normal,
        fontSize = 20.sp,
        letterSpacing = 0.5.sp
    )
)
If I change the fontsize on my own typography, it also seems to affect Texts where I specify a
MaterialTheme
style
Copy code
Text(text = row.nome, style = MaterialTheme.typography.body1, fontWeight = FontWeight.Bold)
I was expecting it would only affect Text where my own typography is specified:
Copy code
Text(text = row.nome, style = typography.body1, fontWeight = FontWeight.Bold)
How is it supposed to work?
h

Halil Ozercan

10/22/2020, 12:26 PM
Is there any chance that you may be passing your own typography instance to MaterialTheme as well?
d

Daniele B

10/22/2020, 12:28 PM
It doesn’t seem so.
I checked again. I also changed the name to
myTypography
, but it’s still affecting Text components styled with
MaterialTheme.typography
. Very strange to me
b

Bryan Herbst

10/22/2020, 1:24 PM
Are you using the
MaterialTheme
composable somewhere? If so, what values are you passing to it for color, typography, and shape?
d

Daniele B

10/23/2020, 3:02 PM
@Bryan Herbst you are right, I just realized!!! the composable was so defined:
Copy code
@Composable
fun MyAppTheme(coreViewModel: CoreViewModel, darkTheme: Boolean = isSystemInDarkTheme(), content: @Composable() () -> Unit) {

    val themeColors : Colors = if (darkTheme) {
        getThemeColors(coreViewModel.themes.DarkColorPalette, false)
    } else {
        getThemeColors(coreViewModel.themes.LightColorPalette, true)
    }

    MaterialTheme(
        colors = themeColors,
        typography = myTypography,
        shapes = shapes,
        content = content
    )
}
thanks! now the mystery is solved!
2 Views