在XML中设置文本外观后设置自定义字体不起作用



我有此文本视图:

<TextView
    android:id="@+id/titleTextView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textAppearance="@style/Paragraph3"
    tools:text="Título"/>

使用此扩展名之后尝试以编程方式应用自定义字体:

fun TextView.setCustomFont(font: Int) {
   typeface = ResourcesCompat.getFont(context, font)
}

但是它不起作用,如果我从xml中删除textappearence,一切都有效。

有什么想法?

更新1

已经遵循文档设置字体:https://developer.android.com/guide/topics/ui/look-and-hook-and-feel/fonts-in-xml

i从XML中求解此删除TextAppeArence并在我的代码中执行SetTextAppeArence。由于该textAppeArence xml属性似乎覆盖了所有字体自定义。

这似乎可以管理它。

最新更新