Search code examples
androidfontsandroid-support-libraryfont-facefont-family

android fontFamily fallback font for missing glyphs


When using new Custom Font on Android with Android Support Library, I'm getting a display issue on Android 4.1 (API 16) while it works OK on 8.0 (API 26):

API 16, NOK API 26, OK

Here is activity_main.xml content, using custom font AvenirNext Medium (stored in res/font/avenirnext_medium.ttf):

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:fontFamily="@font/avenirnext_medium"
            android:text="Hello world?"/> <!-- this is an unbreakable space -->
    </LinearLayout>

I'm targeting SDK 26 while supporting down to SDK 16.

What can I do to get rid of the replacement character '�' in API 16?


Solution

  • Thanks to @HermantParmar comment, it looks like special characters like unbreakable spaces must appears via unicode value (\u00A0). So I modified text attribute and it's now working fine:

    android:text="Hello\u00A0world?"/>