我需要尝试安卓Q的新功能(Android Q和AppCompat v1.1.0默认关闭连字符),并且我也阅读了文档。当我按照安卓博客中的指示操作时,一切正常,但当我尝试按照文档进行操作时,遇到了错误。
我只使用了一个字体族。以下是正在运行的代码:
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中给出。
那么,您能否帮我解决这个错误?