简体   繁体   English

Android密码字段-输入始终隐藏

[英]Android password fields - input hidden at all times

As most of you know, at the moment, the password field works in a way that it hides the input, but not right away. 众所周知,目前,密码字段的工作方式是隐藏输入,但不是立即隐藏。 As you input a character, it shows that character, then a moment later turns it into a * , I'm wondering if there's a way to incorporate a functionality that makes the characters stars at all times. 当您输入一个字符时,它会显示该字符,然后过一会儿将其转换为* ,我想知道是否存在一种方法可以合并一个使字符始终为星状的功能。

Any ways of doing this? 有什么办法吗?

Don't set the default edit text property as password. 不要将默认的编辑文本属性设置为密码。 Instead, you can use addTextChangedListener() which will get called as soon as the user enters a character. 相反,您可以使用addTextChangedListener() ,只要用户输入一个字符,就会立即调用它。 Maintain an activity level string say "mPass". 保持活动级别字符串,例如“ mPass”。 In the TextWatcher() , onTextChanged method, append character to your mPass and replace the input character by *. TextWatcher() onTextChanged方法中,将字符追加到您的mPass并将输入字符替换为*。

But you will have to be careful regarding this because application will pass control to the TextWatcher() even after you have replaced the character by *. 但是您对此必须要小心,因为即使您用*替换了字符,应用程序也会将控制权传递给TextWatcher() If not handled properly it will get called recursively causing the application to crash. 如果处理不当,它将被递归调用,从而导致应用程序崩溃。

Credit to Pallavi 归功于Pallavi

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

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