Edittext set for password with phone number input?

2019-01-12 01:43发布

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?

5条回答
虎瘦雄心在
2楼-- · 2019-01-12 02:16

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.

查看更多
仙女界的扛把子
3楼-- · 2019-01-12 02:27

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.

查看更多
何必那么认真
4楼-- · 2019-01-12 02:31

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

查看更多
▲ chillily
5楼-- · 2019-01-12 02:32

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.

查看更多
我只想做你的唯一
6楼-- · 2019-01-12 02:39

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" />
查看更多
登录 后发表回答