如何将EditText inputType指定为数字和密码?

Kev*_*ood 24 android android-widget

我有以下内容:

<EditText
    android:inputType="number"
    android:password="true"
    ....
</EditText>
Run Code Online (Sandbox Code Playgroud)

我收到一条警告,"android:password"已被弃用,我应该使用inputType.有没有办法将inputType指定为数字和密码?

woy*_*aru 40

android:inputType="numberPassword"

请参阅此链接

  • 我的目标是api 8(2.2及以上).看起来numberPassword不是可用选项. (2认同)

oca*_*nal 18

你应该使用TYPE_CLASS_NUMBER.

编辑:

作为这个答案

android:inputType="textPassword|number" 
Run Code Online (Sandbox Code Playgroud)

忽略textPassword并且只接受数字接受密码.

所以,你应该用android:inputType="textPassword|number"android:password="true".

这似乎是唯一的解决方案.


Bob*_*ke4 2

只需将您的输入类型设置为此android:inputType="textPassword|number"

  • 这似乎不起作用。我仍然有数字键盘,但用户仍然可以看到文本。 (4认同)