Android XML 中的字体不适用于 7.0

Android Fonts in XML not working on 7.0

大家好, 我在 xml 中为我的应用程序使用了 Fonts。它在 7.0 以下的 android 版本上运行良好。但不适用于 7.0。我在 drawable 中创建了一个字体文件夹,并将我所有的字体都放在那里。然后创建了一个这样的字体系列。

 <?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">
    <font
        android:font="@font/timeburnerbold"
        android:fontStyle="normal"
        android:fontWeight="400"
        app:font="@font/timeburnerbold"
        app:fontStyle="normal"
        app:fontWeight="400" />
    <font
        android:font="@font/typo_grotesk_bold"
        android:fontStyle="normal"
        android:fontWeight="700"
        app:font="@font/typo_grotesk_bold"
        app:fontStyle="normal"
        app:fontWeight="700" />
</font-family>

我的Gradle文件信息

compileSdkVersion 27
buildToolsVersion "26.7.2"
supportLibraryVersion = '27.0.0'

我正在整个应用程序中使用它。它在 6.0 及以下版本的应用程序中完美运行。但不是在 7.0 上。不知道我在这里错过了什么。有人吗?

这很奇怪,但我找到了解决办法。似乎是 SDK 中的错误。在字体系列中,如果您有两种不同系列的字体,如下所示 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">
    <font
        android:font="@font/timeburnerbold"
        android:fontStyle="normal"
        android:fontWeight="400"
        app:font="@font/timeburnerbold"
        app:fontStyle="normal"
        app:fontWeight="400" />
    <font
        android:font="@font/typo_grotesk_bold"
        android:fontStyle="normal"
        android:fontWeight="700"
        app:font="@font/typo_grotesk_bold"
        app:fontStyle="normal"
        app:fontWeight="700" />
</font-family>

此类文件在 7.0 及更高版本上将无法使用。 将其更改为

<?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">
    <font
        android:font="@font/typo_grotesk_regular"
        android:fontStyle="normal"
        android:fontWeight="400"
        app:font="@font/typo_grotesk_regular"
        app:fontStyle="normal"
        app:fontWeight="400" />
    <font
        android:font="@font/typo_grotesk_regular"
        android:fontStyle="italic"
        android:fontWeight="400"
        app:font="@font/typo_grotesk_regular"
        app:fontStyle="italic"
        app:fontWeight="400" />
    <font
        android:font="@font/typo_grotesk_bold"
        android:fontStyle="normal"
        android:fontWeight="700"
        app:font="@font/typo_grotesk_bold"
        app:fontStyle="normal"
        app:fontWeight="700" />
    <font
        android:font="@font/typo_grotesk_bold"
        android:fontStyle="italic"
        android:fontWeight="700"
        app:font="@font/typo_grotesk_bold"
        app:fontStyle="italic"
        app:fontWeight="700" />
</font-family>

真正适用于所有 api。一个字体系列文件中的相同字体系列。不知道为什么会这样。