Hebrew and normal text not displaying right

我的未来我决定 提交于 2019-12-12 03:33:15

问题


I'm trying to display Hebrew and normal text mixed, the text comes from a SQLite database and is displayed in a listview that gets pulled from my database in the Assets folder.

I want to display the following:

‘אנא אנא - Ek is, was, sal wees Wie Ek is, was, sal wees.”

But it gets displayed as:

”.Ek is, was, sal wees Wie Ek is, was, sal wees - אנא אנא‘

When the hebrew text is between other normal text its fine like:

‘He says אנא אנא - I am, was, shall be Who I am, was, shall be.”

The text only gets mixed up when the listview item starts with Hebrew.

I've tried:

‘<\U+200f>אנא אנא<\U+200f> - Ek is, was, sal wees Wie Ek is, was, sal wees.”

‘<\U200f>אנא אנא<\U200f> - Ek is, was, sal wees Wie Ek is, was, sal wees.”

‘\U200fאנא אנא\U200f - Ek is, was, sal wees Wie Ek is, was, sal wees.”

‘(\U200f)אנא אנא(\U200f) - Ek is, was, sal wees Wie Ek is, was, sal wees.”

‘<\U+202b>אנא אנא<\U+202b> - Ek is, was, sal wees Wie Ek is, was, sal wees.”

‘<\U202b>אנא אנא<\U202b> - Ek is, was, sal wees Wie Ek is, was, sal wees.”

‘\U202bאנא אנא\U202b - Ek is, was, sal wees Wie Ek is, was, sal wees.”

‘(\U202b)אנא אנא(\U202b) - Ek is, was, sal wees Wie Ek is, was, sal wees.”

‘<\U+202e>אנא אנא<\U+202e> - Ek is, was, sal wees Wie Ek is, was, sal wees.”

‘<\U202e>אנא אנא<\U202e> - Ek is, was, sal wees Wie Ek is, was, sal wees.”

‘\U202eאנא אנא\U202e - Ek is, was, sal wees Wie Ek is, was, sal wees.”

‘(\U202e)אנא אנא(\U202e) - Ek is, was, sal wees Wie Ek is, was, sal wees.”

But everything gets displayed with the codes like: (I dont want to see the codes)

‘<\U+200f>אנא אנא<\U+200f> - Ek is, was, sal wees Wie Ek is, was, sal wees.”

Ive tried android:supportsRtl="true" in the manifest, this only affects the text allignment in my case and not the texts.


回答1:


The issue is that you're mixing an rtl and an ltr text in the same string. The system looks at the string to be displays and see it starts with hebrew. So it starts it in RTL mode. It then sees english text. So it switches to LTR. THe result is what you see. You need to put in explicit unicode ltr and rtl marks when mixing languages like this to ensure that its treated correctly. See https://en.wikipedia.org/wiki/Left-to-right_mark for info on ltr marks.




回答2:


Sooo... This finally worked for me....

textview.setTextDirection(View.TEXT_DIRECTION_LTR);

Please note that my problem was as I said, Im reading data from a database and not displaying strings, so this code forces all data to be read from left to right, if I do not use this line, It picks up the Hebrew characters as RTL text and wants to display the whole result as RTL.

Thanks for all the help though! I had a lot of reading and learned in the process!




回答3:


See the answer here....

Ted Hopp answer

I am using the \u200e for right to left

take your string in string.xml

<string name="Yourstring">\u200e שלום</string>


 TextView text2=(TextView)findViewById(R.id.text2);

 String str= getResources().getString(R.string.Yourstring)+" is the same as hello";
 text2.setText(str);

The result as you want

AS you want if you want for database I am adding some demo with the array data you can do these type work with database value

 String[] str_array={"שלום is the same as hello","שלום is the same as hello","שלום is the same as hello","שלום is the same as hello"};


        TextView text1=(TextView)findViewById(R.id.text1);
        TextView text2=(TextView)findViewById(R.id.text2);
        TextView text3=(TextView)findViewById(R.id.text3);
        TextView text4=(TextView)findViewById(R.id.text4);



        String str="";

        for(int i=0;i<str_array.length;i++)
        {
            if(i==0)
            {

              // before text you want than do this
                text1.setText(str.concat("\u200e")+str_array[i]);
            }
            else if(i==1)
            {
                // add this for end of string

                text2.setText(str_array[i].concat("\u200e"));
            }
            else if(i==2)
            {
           // before text you want than do this
                text3.setText(str.concat("\u200e")+str_array[i]);
            }
            else if(i==3)
            {
           // before text you want than do this
                text4.setText(str.concat("\u200e")+str_array[i]);
            }
        }

The result




回答4:


android:supportsRtl="true"

Means you want Right to Left Support for Arabic ,Hebrew Like Language. which is start with RTL Right to left , when System get that Language is Hebrew,it starts with right.As per my Suggestion you need to define that did you really need RTL support in your app. otherwise please set android:supportsRtl="false" so its start Left to right.



来源:https://stackoverflow.com/questions/39382748/hebrew-and-normal-text-not-displaying-right

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