Android cursor in RTL languages

I have a problem with android input cursor in RTL languages. When I am in the RTL support layout, I have two input cursors, and this is really funny. Does it have a real solution to get rid of it?

I use this code to make my android UI RTL:

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

And this is 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

+5
source share
3 answers

I am solving a problem. Just change the editing language from left to right and the problem will be 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.

+1
source

I decided to use it below.

In your xml layout for edit text field add this ->

 android:textDirection="anyRtl" 

Here "editText" is your text edit field. those.

 EditText editText = (EditText) findViewById(R.id.edit_text); 

Then programmatically add a text observer for this edit text.

 editText.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { editText.setSelection(s.length()); // this line is very important for setting cursor position } @Override public void afterTextChanged(Editable s) { } }); } 

It worked for me!

0
source

Saving android:inputType="phone" instead of android:inputType="number" solved my problem.

The following snippet from my xml:

 <EditText android:hint="xyzz" android:inputType="phone" android:id="@+id/num" android:textColorHint="#000000" android:layout_gravity="start" android:textAlignment="viewStart" android:textDirection="rtl" android:layout_height="fill_parent" android:gravity="center_vertical" android:layout_width="match_parent" tools:ignore="RtlCompat" /> 
0
source

Source: https://habr.com/ru/post/1242940/


All Articles