我必须尝试 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()
Run Code Online (Sandbox Code Playgroud)
但是当我尝试添加多个字体系列时,我遇到了错误。
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();
Run Code Online (Sandbox Code Playgroud)
那么你能帮我解决这个错误吗?
android ×1