androidandroid-layoutandroid-fontsunicode-literals

Displaying the unicode characters with real devices and emulators


Some unicode characers don't display on real devices and emulators but stay displaying within Android Studio design mode. For example, In design mode: enter image description here

but the emulator (as well as real device) shows nothing: enter image description here

So, why this is it? And, what should I do to gain the expected result?

UPD: As one of perheps solution I tryied to use androidx.emoji2:emoji2 library. And this helped me bit. But this is poor efficiency as for me. Because using proposed bundle upsize my app from 1.5Mb up to 22Mb. Using the downloadable font provider may solve this, but as it says:

"The initializer creates a background thread to load the emoji font, and font download may take up to 10 seconds before timing out. After the font is downloaded, it takes approximately 150 milliseconds on a background thread to initialize EmojiCompat."

So, although I wanted to use unicode benifits to avoid using additional graphic resources, but now I have no another idea as to use vector resources for my aim.

If anyone had other experiences in this area, please, share here.


Solution

  • I think it's a font issue. The font used by Android studio may not supports that character while the android device, you will need to embed a font which support that character.

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="\u270c"
        android:textSize="50dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
    

    This code worked for me and below one was the result in emulator PIXEL 5 API 32 enter image description here

    Also, it seems to be device specific. Troubles with Unicode string encoding in Android