0

I have an edit text field, which I need to format every word to hashtag

Example if I type ABC it should be formatted to #ABC

I’ve implemented it with input filter but I’m not able to manage it when user enter Arabic text, #abc# مرحبا #مرحبا appears like this, I assume I can solve the problem if I can force the EditText android:textDirection="ltr", but even after this change android EditText behaving rtl when input is Arabic text.

So my question is, how to force an EditText to behave ltr even for rtl text inputs like Arabic?

1'hafs
  • 559
  • 7
  • 25

2 Answers2

0

To make for both direction automatically use below codes

android:layout_gravity="start"
android:textAlignment="viewStart"
Roman
  • 2,464
  • 2
  • 17
  • 21
0

Please refer it on the following site for more description Very nice blog by: Sven Bendel or his github page

/**
     * Reformat the String as LTR to ensure that it is laid out from
     * left to right, but it doesn't affect overall layouting of
     * TextViews etc..
     */
    public static String makeLtr ( String string ) {
       if (checkRtl(string)) {
            /* prepend the string with an LTR control sign (so
               that Android's RTL check returns false) and an RTL
               control sign (so that the string itself is printed in
               RTL) and append an LTR control sign (so that if we
               append another String it is laid out LTR). */
            return "\u200E" + "\u200F" + string + "\u200E";
        } else {
            return string;
        }
    }

    /**
     * Check if the given String is probably written in RTL by
     * checking if the very first character is within the range of
     * RTL unicode characters.
     */
    public static boolean checkRtl ( String string ) {
        if (TextUtils.isEmpty(string)) {
            return false;
        }
        char c = string.charAt(0);
        return c >= 0x590 && c <= 0x6ff;
    }

Kidus Tekeste
  • 651
  • 2
  • 10
  • 28