dan.the.man
10/14/2021, 5:59 PM@Composable
fun MyTheme(
content: @Composable () -> Unit
) {
MaterialTheme(
typography = Typography(appFontFamily),
content = content
)
}
Using this, it correctly applies the font family if I do a normal text, but as soon as I apply a TextStyle to a Text
, it doesn't apply that default font family anymore
val displayJumboBold = TextStyle(
fontSize = 40.sp,
fontWeight = FontWeight.Bold,
lineHeight = 48.sp
)
I assume this is because the TextStyle defaults to null for font family if I don't explicitly set it, but should it not fall back to the default of the Theme that I've set?Chris Sinco [G]
10/14/2021, 6:28 PMnull
- that ends up resolving back to the DefaultFontFamily of the system (in the implementation of TextStyle), and not from the theme. This is intentional since Compose allows you to override styles at that local composition scope, which in this case is null
.Chris Sinco [G]
10/14/2021, 6:29 PMdan.the.man
10/14/2021, 6:33 PMappFontFamily
Chris Sinco [G]
10/14/2021, 6:33 PMdisplayJumboBold
but you don’t want to change fontFamily?dan.the.man
10/14/2021, 6:33 PMText(style = displayJumboBold)
ends up changing the font back as if I never set the default. Text()
displays correctly with the appFontFamily
applieddan.the.man
10/14/2021, 6:34 PMdisplayJumboBold
to not change the font of the Text
it's applied otChris Sinco [G]
10/14/2021, 6:38 PMLouis Pullen-Freilich [G]
10/14/2021, 6:54 PMTypography
, there is no way to set a global default font family in this way. Might be easiest to create your own Text()
implementation that sets it if it is missing from the style