在 AndroidX 上,可以使用以下代码示例来解决 androidx.appcompat.widget.AppCompatTextView 中的 fontFamily 不起作用的问题:
res/values/styles.xml 文件中定义一个自定义的样式:
res/layout/your_layout.xml 文件中的相应的 TextView 上应用这个样式:
res/font 目录下添加字体文件,例如 my_font.ttf。确保将 my_font.ttf 放在正确的文件夹内,并且在 CustomTextViewStyle 中正确引用它。
这样,fontFamily 应该会正确应用到你的 AppCompatTextView 上。