我有下一个风格:
<style name="Text.Light">
<item name="android:fontFamily">@font/open_sans_light</item>
</style>
如果我在设计时通过 textAppearance
将它设置为 TextView
就像 android:textAppearance="@style/Text.Italic"
它显示斜体字体,但在运行时它不影响。但是,如果像 android:fontFamily="@font/open_sans_italic"
一样直接在 TextView 中使用 fontFamily,它在两种情况下(设计和运行时)都能完美运行。
我究竟做错了什么?有我的字体系列 xml:
<?xml version="1.0" encoding="utf-8"?>
<font-family xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:ignore="UnusedAttribute">
<font
android:font="@font/open_sans_regular"
android:fontStyle="normal"
android:fontWeight="400"
app:font="@font/open_sans_regular"
app:fontStyle="normal"
app:fontWeight="400" />
<font
android:font="@font/open_sans_italic"
android:fontStyle="italic"
android:fontWeight="400"
app:font="@font/open_sans_italic"
app:fontStyle="italic"
app:fontWeight="400" />
</font-family>
最佳答案
问题是我在 AppTheme
中选择了 textViewStyle
并且有 fontFamily
。根据post textAppearance
具有最低优先级,它不能覆盖在主题或其他任何地方定义的其他样式。
关于android - fontFamily 属性不能通过 textAppearance 工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57100207/