I am trying to set a font to a text view in android studio but for some reasons, I cannot access the font directory.
I get Unresolved Reference: font
What I did
- Created a new directory by right clicking res > new > Android Resource Directory > Directory name : font > Resource type : font
- Placed my font in that directory, so the directory reads - res/font/myfont.ttf
- In my fragment I tried to access the font like this
var typeFace: Typeface? = ResourcesCompat.getFont(requireContext(), R.font.myfont.ttf)
Error shows Unresolved Reference: font
I tried to rebuild project but still not working.
Use:
typeFace: Typeface? = ResourcesCompat.getFont(requireContext(), R.font.myfont)
Do not add .ttfextension.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With