我正在尝试在 android studio 中为 TextView 设置字体,但由于某些原因,我无法访问字体目录。
我得到Unresolved Reference: font
我做了什么
- 通过右键点击 res > new > Android Resource Directory > Directory name : font > Resource type : font 创建了一个新目录
- 将我的字体放在该目录中,因此该目录读取 - res/font/myfont.ttf
- 在我的 fragment 中,我尝试像这样访问字体
var typeFace: Typeface? = ResourcesCompat.getFont(requireContext(), R.font.myfont.ttf)
错误显示Unresolved Reference: font
我尝试重建项目,但仍然无法正常工作。
最佳答案
使用:
typeFace: Typeface? = ResourcesCompat.getFont(requireContext(), R.font.myfont)
不要添加.ttf
扩展名。
关于android - Unresolved reference : font in Android Studio,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64114911/