简体   繁体   English

为电话号码输入设置密码的Edittext? (机器人)

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

How do I get a Edittext with both a phone input and the ability to hide the string. 如何使用手机输入和隐藏字符串的功能获取Edittext。 I know that 我知道

android:inputType="textPassword"

hides the string, while 隐藏字符串,而

android:inputType="phone"

brings up a dialpad interface. 打开拨号盘界面。

How to combine the two? 如何将两者结合起来?

android:password is deprecated, but AFAIK is the only way because android:inputType="phone|textPassword" is ignored ... android:password已被弃用,但AFAIK是唯一的方法因为android:inputType="phone|textPassword"被忽略了...

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

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. 编辑:在问题(2010年)时,这可能不在API中,但对于当代开发,它是可用的。

I have not found an appropriate solution to this problem. 我还没有找到解决这个问题的合适方案。 dtmilano's accepted solution doesn't fully work. dtmilano接受的解决方案并不完全有效。 If the EditText is focused in landscape mode where you have the full screen keyboard, the numbers still display in clear text, not masked. 如果EditText在横向模式下聚焦,您可以使用全屏键盘,则数字仍以明文显示,而不是屏蔽。

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. 我花了很多时间浏览实际的TextView代码,这是一个问题的原因是他们显式检查InputType.TYPE_CLASS_TEXT的InputType,如果我没记错的话,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. 因此,如果在这些边界中包含任何其他InputType(我认为TYPE_CLASS_TEXT和TYPE_MASK_CLASS使用的范围是第一个字节),那么它将不会被识别为需要屏蔽的密码。

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. 说实话,我对TextView的代码感到非常震惊。 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 . 没有使用弃用的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. 因为inputType可以采用多个值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM