简体   繁体   中英

Right-to-Left characters reversed in Android Emulator

It'ss my first time developing an app in a RTL language (Hebrew). I've been struggling for two days with reversed characters.

My String XML:

<resources>
   <string name="app_name">SomeApp</string>

   <string name="hello_world">מה המצב?</string>
   <string name="action_settings">Settings</string>
</resources>

With the string hello_world I want to create a textView which will use this string. The result should be:

?מה המצב

However the emulator shows:

模拟器

As you can see its not only change the order of the sentence and the question mark. it also changing the order of the letters.

Things I have tried so far:

  1. API level 20 and above. Some places implied that the problem is known in fixed after 4.2 version.
  2. Using the mark \‏ in begin or end or both of a sentence.
  3. Using \‎ after each special char like " , , , . , ? , ! , etc. When I write in Hebrew without special chars at all everything works fine.

activity_my.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"        android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MyActivity"
android:id="@+id/StudentLife">

<TextView android:text="@string/hello_world"             android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/textView"
    android:layout_alignParentTop="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true" />

   </RelativeLayout>

I've searched around but nothing works, maybe I missed something.

The screenshot shows not an emulator, but the visual layout manager of Android Studio. This seems to be a weird bug in the layout manager, but it will not effect the application - whether on emulator or on a real device.

You are right, RTL support prior to Android 4.2 was not standardized, and some devices may perform in a strange way. But the emulator even for 2.3.3 does not revert the Hebrew letters for me.

Well, it does not put ? on the left, and you need to append \‏ to cure this. But for 4.2 and higher, you can specify android:textDirection="rtl" instead of the mark.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM