d

    Daniele B

    1 year ago
    There is something I don’t understand about Theming. I have defined my own typography:
    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
    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:
    Text(text = row.nome, style = typography.body1, fontWeight = FontWeight.Bold)
    How is it supposed to work?
    Halil Ozercan

    Halil Ozercan

    1 year ago
    Is there any chance that you may be passing your own typography instance to MaterialTheme as well?
    d

    Daniele B

    1 year ago
    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
    Bryan Herbst

    Bryan Herbst

    1 year ago
    Are you using the
    MaterialTheme
    composable somewhere? If so, what values are you passing to it for color, typography, and shape?
    d

    Daniele B

    1 year ago
    @Bryan Herbst you are right, I just realized!!! the composable was so defined:
    @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!