Search code examples
androidlayoutright-to-lefttext-cursor

Android cursor in RTL languages


I have problem with android input cursor in RTL languages. When I am in RTL support layout, I have two input cursor and it's really funny. Does it have real solution, for get rid of this?

I use this code to make my android UI RTL:

getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL);

And this my xml for text view:

<android.support.design.widget.TextInputLayout
        android:id="@+id/input_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="numberDecimal"
            android:id="@+id/myID"
            android:maxLines="1"
            android:focusableInTouchMode="true"
            android:layout_weight="0.25"
            android:layout_gravity="center_horizontal"
            android:hint="phone Number"
            android:maxLength="20"
            android:gravity="center" />
    </android.support.design.widget.TextInputLayout>

enter image description here


Solution

  • I solve the problem. Just make the edit text language left to right and problem is solved.

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:inputType="number"
        android:ems="10"
        android:id="@+id/PhoneNoET"
        android:layout_marginTop="64dp"
        android:layout_below="@+id/textView6"
        android:layout_centerHorizontal="true"
        android:textAlignment="center"
        android:maxLength="11" 
        android:layoutDirection="ltr"/>
    

    Add the above layoutDirection to your Edit Text and fix the problem.