Question

How do I get a Edittext with both a phone input and the ability to hide the string. I know that

android:inputType="textPassword"

hides the string, while

android:inputType="phone"

brings up a dialpad interface.

How to combine the two?

Was it helpful?

Solution

android:password is deprecated, but AFAIK is the only way because android:inputType="phone|textPassword" is ignored ...

<EditText
    android:id="@+id/EditText01"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:password="true"
    android:inputType="phone" />

OTHER TIPS

I believe this is what you want?

android:inputType="numberPassword"

Edit: At the time of the question (2010) this may have not been in the API, but for contemporary development, it's available.

I have not found an appropriate solution to this problem. dtmilano's accepted solution doesn't fully work. If the EditText is focused in landscape mode where you have the full screen keyboard, the numbers still display in clear text, not masked.

I spent significant time going through the actual TextView code, and the reason this is a problem is that they are explicitly checking the InputType against InputType.TYPE_CLASS_TEXT and, if I recall correctly, TYPE_MASK_CLASS. So if you include any other InputType within those bounds (I think the range used by TYPE_CLASS_TEXT and TYPE_MASK_CLASS is the first byte), then it won't be recognized as a password that needs masking.

I know what I said is pretty confusing. The actual code is a LOT more confusing. I was pretty appalled at the TextView's code to be honest. It's a tangled mess, with hard coded checks everywhere. Horrible coding practice which leads to problems like this.

This problem can be solved without using deprecated android:password. See my answer here.

I haven't tried this, but it might be possible to combine the two like so:

android:inputType="textPassword|phone"

since inputType can take on multiple values.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top