I haven't implemented it with the new 1.6 way, but that shows it needing to be called from a composable. You could either create the font in a composable function and access it elsewhere or set it up at the top level as a compositionLocal
val LocalFont = compositionLocalOf<FontFamily?> {null}
@Composable
fun MainView() {
val fontFamily = FontFamily(Font(Res.font.yourfont, weight = FontWeight.Bold))
CompositionLocalProvider(
LocalFont provides fontFamily
) {
Text("hello", fontFamily = LocalFont.currentOrThrow)
}
You could also just make a composable function that returns it
@Composable
fun someFont(): FontFamily {
return FontFamily(Font(Res.font.yourfont, weight = FontWeight.Bold))
}
Text(text = "hello", fontFamily = someFont())