【问题标题】:How do I specify EditText inputType as number and password?如何将 EditText inputType 指定为数字和密码?
【发布时间】:2012-04-10 10:50:39
【问题描述】:

我有以下几点:

<EditText
    android:inputType="number"
    android:password="true"
    ....
</EditText>

我收到警告说“android:password”已被弃用,我应该改用 inputType。有没有办法将 inputType 指定为数字和密码?

【问题讨论】:

标签: android android-widget


【解决方案1】:

设置android:inputType="numberPassword"

看到这个Link

【讨论】:

  • 我的目标是 api 8(2.2 及更高版本)。看来 numberPassword 不是一个可用的选项。
【解决方案2】:

你应该使用TYPE_CLASS_NUMBER

编辑:

作为this answer

android:inputType="textPassword|number" 

忽略 textPassword 并且只接受号码不接受密码

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

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

【讨论】:

  • android:password="true" 已弃用。 android:inputType="numberPassword" 会起作用。
【解决方案3】:

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

【讨论】:

  • 这似乎不起作用。我还有数字键盘,但用户仍然可以看到文字。
猜你喜欢
  • 1970-01-01
  • 2019-06-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-13
  • 1970-01-01
  • 2013-09-20
相关资源
最近更新 更多