1

After adding downloadable fonts using android studio (based on https://stackoverflow.com/a/47793223), Im not able to load the added fonts programmatically.

ResourcesCompat.getFont(context, R.font.roboto)

results in the following error

android.content.res.Resources$NotFoundException: Font resource ID #0x7f080009
at android.support.v4.content.res.ResourcesCompat.loadFont(ResourcesCompat.java:218)
at android.support.v4.content.res.ResourcesCompat.getFont(ResourcesCompat.java:196)

But once I specify the same font in some layout file like

android:fontFamily="@font/roboto"

It works.

It also starts working programmatically now.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Thiagesh thg
  • 100
  • 7

1 Answers1

0

In order to access the font programmatically, you need to create a font request.

Read this official documentation.

If you think that's lengthy process, you can always specify it in the xml and set its visibility to Gone if you don't need the view.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Samuel Robert
  • 10,106
  • 7
  • 39
  • 60