我们注意到很多“无法加载字体”崩溃,特别是在运行 Android 13 的三星 Galaxy S22 Ultra 上。到目前为止,我们无法自己重现它。我在谷歌上搜索了很多,但没有找到这样的东西。
这就是我们在 Jetpack Compose 中使用字体的方式:
@Composable
fun AppTheme(darkTheme: Boolean = isSystemInDarkTheme(), content: @Composable () -> Unit) {
MaterialTheme(
colors = if (darkTheme) DarkColors else LightColors,
typography = DinProTypography,
shapes = AppShapes,
content = content)
}
Run Code Online (Sandbox Code Playgroud)
val DinProTypography = Typography(
h1 = TextStyle(
fontFamily = DinPro,
fontWeight = FontWeight.Light,
fontSize = 30.sp))
Run Code Online (Sandbox Code Playgroud)
val DinPro = FontFamily(
Font(R.font.dinpro_light, FontWeight.Light),
Font(R.font.dinpro_medium, FontWeight.Medium),
Font(R.font.dinpro_regular, FontWeight.Normal),
Font(R.font.dinpro_bold, FontWeight.Bold)
)
Run Code Online (Sandbox Code Playgroud)
这是堆栈跟踪:
Fatal Exception: java.lang.IllegalStateException: Could not load font
at …
Run Code Online (Sandbox Code Playgroud)