Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Double cursor in EditText for Input Type Number/Phone (RTL Arabic)

I have an EditText set to gravity Right, so that the text starts from the right if the language is Arabic.

Note: My application supports RTL, and I am not setting the TextDirection for my EditText as that will have the same problem. Gravity set to Right does the job perfectly. I have an issue only if I set the InputType to Number or Phone.

If the InputType is set to number/phone there are double cursor at the beginning and end of the text and it is a bit confusing.

To demonstrate this, I have two EditText with InputType Text and Number, Gravity set to Right for both. My application supports RTL and My phone is now set to Arabic language

Manifest

android:supportsRtl="true"

XML

 <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="text"
            android:inputType="text"
            android:lines="1"
            android:maxLines="1"
            android:gravity="right"
            />

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/phone"
            android:inputType="number"
            android:lines="1"
            android:maxLines="1"
            android:gravity="right"
            />

Here is a screen shot of the behaviour for the second EditText with InputType Number.

Any pointers on how to get rid of the double cursor? or any alternative.

Thanks R

enter image description here

like image 660
BRDroid Avatar asked Jan 29 '18 09:01

BRDroid


2 Answers

Use properties layout_direction as 'ltr' and gravity 'right'.

      <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/phone"
            android:inputType="number"
            android:lines="1"
            android:maxLines="1"
            android:gravity="right" />

This solved my problem.

like image 96
Viswas Kg Avatar answered Oct 14 '22 21:10

Viswas Kg


The Edit text doesn't know if the next char you will press is a number or a letter so in case of a letter it places the far left one while the far right one for a number(Most likely you know that just making sure).

So it will disappear if you switch to English.

I think this is fundamental in the edit text:

Solutions:

1- You can create your own edit text from scratch(From View).(May take month with all the problems that may arise).

2- Find a way to override the edit text to remove the split.

3- Find a git where someone had solved that problem(which I doubt).


This doesn't seem like a problem as a programmer or a user. A designer maybe will be a bit annoyed but ignoring it is the fastest way.

Sorry if this wasn't usefull.

like image 23
Mohammad Tabbara Avatar answered Oct 14 '22 22:10

Mohammad Tabbara