fontFamily не работает должным образом на уровне API ниже 24 - PullRequest
0 голосов
/ 30 октября 2018

Я сталкиваюсь с проблемой рендеринга шрифтов при использовании Шрифты в XML

В следующем файле семейства шрифтов предполагается выбрать шрифт roboto_regular при использовании без атрибута android:textStyle и roboto_medium при использовании с атрибутом android:textStyle="bold":

roboto.xml

<font-family xmlns:app="http://schemas.android.com/apk/res-auto">
    <font
        app:font="@font/roboto_regular"
        app:fontWeight="400" />

    <font
        app:font="@font/roboto_medium"
        app:fontWeight="700" />
</font-family>

Макет с использованием этого семейства шрифтов:

<TextView
     android:id="@+id/textView"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:fontFamily="@font/roboto"
     android:text="Roboto font family"
     android:textSize="16sp" />

<TextView
     android:id="@+id/textView2"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:fontFamily="@font/roboto"
     android:text="Roboto font family bold"
     android:textSize="16sp"
     android:textStyle="bold" />

<TextView
     android:id="@+id/textView3"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:fontFamily="@font/roboto_regular"
     android:text="Roboto Regular"
     android:textSize="16sp" />

<TextView
     android:id="@+id/textView4"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:fontFamily="@font/roboto_medium"
     android:text="Roboto Medium"
     android:textSize="16sp" />

Это работает так, как задумано на Android 27 и 25, но дополнительный жирный эффект применяется на Android <25 (см. Скриншоты для Android 21 и 23). </p>

Рендеринг API 27:

API 27 rendering

API 25 рендеринг:

API 25 rendering

Рендеринг API 23:

API 23 rendering:

API 21 рендеринг:

API 21 rendering

Проблема становится более очевидной при установке другого шрифта для fontWeight="700", как показано в

custom_font_family.xml

<font-family xmlns:app="http://schemas.android.com/apk/res-auto">
    <font
        app:font="@font/roboto_regular"
        app:fontWeight="400" />

    <font
        app:font="@font/poor_story_regular"
        app:fontWeight="700" />
</font-family>

И соответствующая выписка макета:

<TextView
  android:id="@+id/textView5"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:fontFamily="@font/custom_font_family"
  android:text="Custom font family"
  android:textSize="16sp" />

<TextView
  android:id="@+id/textView6"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:fontFamily="@font/custom_font_family"
  android:text="Custom font family bold"
  android:textSize="16sp"
  android:textStyle="bold" />

<TextView
  android:id="@+id/textView7"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:fontFamily="@font/poor_story_regular"
  android:text="Poor story regular"
  android:textSize="16sp" />

<TextView
  android:id="@+id/textView8"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:fontFamily="@font/poor_story_regular"
  android:text="Poor story regular bold"
  android:textSize="16sp"
  android:textStyle="bold" />

Автономный проект, демонстрирующий проблему, доступен здесь: https://github.com/NicoEkino/FontFamilyIssue

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...