Edittext set for password with phone number input? (android)

后端 未结 5 1927
野的像风
野的像风 2020-12-03 17:09

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 th

相关标签:
5条回答
  • 2020-12-03 17:17

    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.

    0 讨论(0)
  • 2020-12-03 17:20

    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.

    0 讨论(0)
  • 2020-12-03 17:24

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

    0 讨论(0)
  • 2020-12-03 17:32

    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" />
    
    0 讨论(0)
  • 2020-12-03 17:34

    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.

    0 讨论(0)
提交回复
热议问题