【发布时间】:2020-05-17 09:07:23
【问题描述】:
我必须在 Android Q 中尝试新功能(在 Android Q 和 AppCompat v1.1.0 中,连字符默认是关闭的)并且我还阅读了文档。当我按照 Android 博客中的说明进行操作时,它可以正常工作,但是当我尝试按照文档进行操作时,我发现了错误。
我只使用一个单一的字体系列。下面的代码正在运行:
tvTest.typeface = Typeface.CustomFallbackBuilder(
FontFamily.Builder(
Font.Builder(resources.assets, "aguafina_script.ttf").build()).build())
.addCustomFallback(FontFamily.Builder(
Font.Builder(resources.assets, "Font_Solid_900.otf").build()).build())
.build()
但是当我尝试添加多个字体系列时,我得到了错误。
Font regularFont = new Font.Builder("regular.ttf").build();
Font boldFont = new Font.Builder("bold.ttf").build();
FontFamily family = new FontFamily.Builder(regularFont)
.addFont(boldFont).build();
Typeface typeface = new Typeface.CustomFallbackBuilder(family)
.setWeight(Font.FONT_WEIGHT_BOLD) // Set bold style as the default style.
// If the font family doesn't have bold style font,
// system will select the closest font.
.build();
以上代码在文档中给出 https://developer.android.com/reference/kotlin/android/graphics/Typeface.CustomFallbackBuilder.html
那么你能帮我解决这个错误吗?
【问题讨论】:
-
请发布完整的错误日志..
-
java.lang.IllegalArgumentException: 字体 {path=null, style=FontStyle { weight=400, slant=0}, ttcIndex=0, axes=, localeList=, buffer=java.nio.DirectByteBuffer [pos=0 lim=656568 cap=656568]} 已经添加到 android.graphics.fonts.FontFamily$Builder.addFont(FontFamily.java:100)
标签: android