I'm facing a font rendering issue while using Fonts in XML
The following font family file is supposed to select roboto_regular font when used without android:textStyle attribute and roboto_medium when used with android:textStyle="bold" attribute:
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>
The layout applying this font family is:
<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" />
This is working as intended on Android 27 and 25, but an extra bold effect is applied on Android < 25 (see screenshots for Android 21 & 23).
API 27 rendering:
API 25 rendering:
API 23 rendering:
API 21 rendering:
The problem is more obvious when setting a different font for fontWeight="700" as seen in
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>
And the corresponding layout extract is:
<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" />
A standalone project demonstrating the issue is available here: https://github.com/NicoEkino/FontFamilyIssue



