2

I am displaying a button that has an leftwards arrow character as it's text. The leftwards arrow is unicode character u2190. The relevant code snippet is the following:

<Button
    app:layout_row="0"
    app:layout_column="2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="\u2190"
    android:textSize="@dimen/font_size"
    app:layout_columnWeight="1"
    style="?android:attr/buttonBarButtonStyle"
    android:onClick="onKeyPressed"
/>

On most devices I am getting the expected result (left image), while on Nokia 1 API Level 27 (available on Firebase Test Lab) I got something that might be some han glyph (right image).

results

How do I ensure that the unicode character is displayed properly on all devices? I would prefer no code, xml only solution.

Viktor Brešan
  • 5,293
  • 5
  • 33
  • 36
  • There can be multiple solutions: 1. You should change the text using code instead of xml 2. Maybe it's dependent on the locale used, see the answer on this link: https://stackoverflow.com/a/31439499/3986289 – Lukáš Anda Dec 19 '22 at 09:11

1 Answers1

0

I have resolved the problem by finding a TTF font with permissive license that had leftwards arrow correctly mapped. I have added it in res/font directory and referenced it from the layout file in the following way:

<Button
    android:fontFamily="@font/custom"
    app:fontFamily="@font/custom"
    app:layout_row="0"
    app:layout_column="2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="\u2190"
    android:textSize="@dimen/font_size"
    app:layout_columnWeight="1"
    style="?android:attr/buttonBarButtonStyle"
    android:onClick="onKeyPressed"
/>

Now the leftwards arrow is displayed properly on testing devices, including the one that previously was showing a different symbol.

Additionally, I used FontForge to subset the font so that it contains only the necessary character.

Viktor Brešan
  • 5,293
  • 5
  • 33
  • 36