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.