android - fontFamily 属性不能通过 textAppearance 工作

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

我有下一个风格:

 <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/

相关文章:

android - 如何在 Android Spinner 中仅显示 3 个字符?

android - 如何在 Kotlin 中用存储的数据填充可编辑的 PDF?

android 跨度点击事件

php - 如何使用Google Map API在Google map 上绘制路线?

android - 在 Google Play 下载我的应用程序时包文件无效

java - android studio Viewpager OnClickListener 不工作

Android 通知不显示超过 3 个操作

android - 由于兼容性问题,Note 9 用户无法下载我们的应用程序

android - 获得布局高度的最佳位置是什么?

android - 创建一个中间带有图标的按钮