Android setting with TextView for Hebrew text?

假装没事ソ 提交于 2019-12-27 12:07:02

问题


I am setting text in TextView from string resource. Normally, Hebrew works in Right-To-Left format. When I set a text, it sets the text Right-To-Left format in LG, Samsung, Sony Phone but in HTC it does not work. It works in Left-To-Right format in HTC. Even I set Gravity to the TextView in Java file.

Text in TextView should be span according to the screen size. For example if it is 320 x 480 then it display in 4 lines but if it is Galaxy Tab then there may be 2 lines.

Here is my Code snippet:

In Java:

private TextView mVersionInfo, mVersionDescriptionOne, mVersionDescriptionTwo, mVersionDescriptionThree;

mVersionInfo = (TextView)findViewById(R.id.VersionInfo);
mVersionDescriptionOne = (TextView)findViewById(R.id.VersionDesc1);
mVersionDescriptionTwo = (TextView)findViewById(R.id.VersionDesc2);
mVersionDescriptionThree = (TextView)findViewById(R.id.VersionDesc3);

mVersionDescriptionOne.setGravity(Gravity.RIGHT);
mVersionDescriptionTwo.setGravity(Gravity.RIGHT);
mVersionDescriptionThree.setGravity(Gravity.RIGHT);

in XML:

<TextView android:id="@+id/VersionDesc1"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:text="@string/versiondesc1" android:textColor="#000000"
        android:layout_marginTop="5dip" android:gravity="right"
        android:layout_alignParentRight="true" android:layout_marginRight="10dip"
        android:layout_below="@+id/Share" android:textSize="13sp"
        android:layout_alignRight="@+id/Body" />
    <TextView android:id="@+id/VersionDesc2"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:text="@string/versiondesc2" android:textColor="#000000"
        android:layout_alignParentRight="true" android:layout_marginRight="10dip"
        android:layout_below="@+id/VersionDesc1" android:textSize="13sp"
        android:layout_marginTop="5dip" android:gravity="right"
        android:layout_alignRight="@+id/Body" />
    <TextView android:id="@+id/VersionDesc3"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:text="@string/versiondesc3" android:textColor="#000000"
        android:layout_alignParentRight="true" android:layout_marginRight="10dip"
        android:layout_below="@+id/VersionDesc2" android:textSize="13sp"
        android:layout_marginTop="5dip" android:gravity="right"
        android:layout_alignRight="@+id/Body" />

In String Resource:

<string name="versiondesc1">האפליקציה מתחברת לאתר הספק הסלולרי כדי להציג את מצב החשבון. לעיתים, כשאתר הספק איננו עובד תקין לא יהיה ניתן לקבל מידע. באם אתר הספק ישתנה האפליקציה עלולה להפסיק לעבוד. במצב כזה האפליקציה תחזור לעבודה תקינה מיד לאחר שאנו נתאים את שרת התוכנה שלנו לשינויים.</string>
<string name="versiondesc2">הערה: אנחנו לא מייצגים את חברות הסלולר ולא נמצאים איתן בקשר מסוג כלשהו!</string>
<string name="versiondesc3">אם נתקלת בבעיה, השתמש/י בכפתור יצירת קשר על מנת שנוכל לפתור אותה. נשמח לקבל כל משוב על האפליקציה.</string>

What is wrong with my code?

Anybody who has worked with another language, Please guide me here.

Thanks.


回答1:


Gravity will only affect alignment and will not set base direction for the text. That it works on some devices and not others may be a font issue, or perhaps an OS version issue. Try adding a RIGHT-TO-LEFT MARK character (\u200F) at the start of your text. This might help the display on an HTC and will not hurt anything on devices where it is already working.




回答2:


here is an example from my hebrew string xml, Thanks to Ted Hopp's answer:

you need to add '\u200e' before the char that causes you the problem:

<string name="basic_text1">המר על תוצאת המשחק\u200e:</string>

and the result will be:

 :המר על תוצאת המשחק


来源:https://stackoverflow.com/questions/6302221/android-setting-with-textview-for-hebrew-text

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!