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>
In your android phone, tap on “Settings” icon. Now tap on developer options and search for “Force RTL layout direction”. Tap on it to enable RTL feature.
Setting the android:textCursorDrawable attribute to @null should result in the use of android:textColor as the cursor color. oh man that is SO much more efficient than conjuring up a drawable for the cursor to be black!!
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.
I resolved it using below..
In your xml layout, for edit text field add this-->
android:textDirection="anyRtl"
Here, "editText" is your view of edit text field. i.e,
EditText editText = (EditText) findViewById(R.id.edit_text);
Then programatically add text watcher for that 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) {
}
});
}
This worked for me!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With