简体   繁体   中英

Android textDirection anyRtl not working for English text

I need an EditText box that shows the entered text (English) from right to left.

So if the user enters the word "him" on the keyboard, the EditText should show the following - first "h" then "ih" and finally "mih".

I thought android:textDirection="anyRtl" would achieve the same. I'm on API level 22.

But it doesn't seem to be working. This is my EditText code:

<EditText
    android:id="@+id/editText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:textDirection="anyRtl"
    android:gravity="right"
    android:fontFamily="@font/digital"
    android:minEms="7"
    android:maxLength="10"
    />

Any reason why rtl or anyRtl isn't working. Am I misunderstanding how it works? How can I achieve my required use-case?

Through Android document:

If the text contains any strong right to left non-format character, determines that the direction is right to left, falling back to left to right if it finds none.

Your input 'him' is obviously an English word, which contains no RTL character. In your case, I think that you may choose "rtl" or "locale".

Seeing: https://developer.android.com/reference/android/text/TextDirectionHeuristics.html

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