可下载字体例外

Downloadable Fonts Exception

我决定在我的项目中使用 Downloadable fonts。我按照指南中的建议实施了所有内容。

当我尝试从 ResourcesCompat 获取字体时出现以下问题:

ResourcesCompat.getFont(MainActivity.this, R.font.roboto_bold)

在那之后,我总是得到这个例外:

Font resource ID #0x7f090005 could not be retrieved

如何解决这个问题?

PS:

  1. 支持兼容库 v27
  2. 最小 SDK 16
  3. 通过 ResourcesCompat.FontCallback 的解决方案对我来说不是一个好方法
  4. 问题出现在有和没有 Google Play 服务
  5. 的设备上

引自https://developer.android.com/guide/topics/ui/look-and-feel/downloadable-fonts.html#via-android-studio

You can set your application to download fonts by using Android Studio 3.0. To help you get started with the Downloadable Fonts features, you can use the font provider from Google Play services.

Note: A device must have Google Play services version 11 or higher to use the Google Fonts provider.