fontFamily属性无法通过textAppearance工作

时间:2019-07-18 17:55:57

标签: android android-studio android-layout android-fonts

我有下一种风格:

 <style name="Text.Light">
        <item name="android:fontFamily">@font/open_sans_light</item>
    </style>

如果在设计时像TextView一样通过textAppearance将它在xml中设置为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>

1 个答案:

答案 0 :(得分:0)

问题是我在textViewStyle中选择了AppTheme,并且有fontFamily。根据{{​​3}},textAppearance的优先级最低,并且不能覆盖主题或其他任何地方定义的其他样式。