如何在隐藏和查看密码之间切换 [英] How to switch between hide and view password

查看:70
本文介绍了如何在隐藏和查看密码之间切换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种聪明的方法可以让用户在android EditText中的隐藏和查看密码之间进行切换? 许多基于PC的应用程序使用户可以执行此操作.

Is there a clever way to let the user switch between hide and view password in an android EditText? A number of PC based apps let the user do this.

推荐答案

您可以动态更改TextView的属性.如果将XML Atrribute android:password设置为true,则如果将其设置为false,则视图将显示点.

You can dynamically change the attributes of a TextView. If you would set the XML Atrribute android:password to true the view would show dots if you set it to false the text is shown.

使用方法 setTransformationMethod 您应该能够从代码中更改此属性. (免责声明:显示该视图后,我尚未测试该方法是否仍然有效.如果遇到问题,请给我留言以供我了解.)

With the method setTransformationMethod you should be able to change this attributes from code. (Disclaimer: I have not tested if the method still works after the view is displayed. If you encounter problems with that leave me a comment for me to know.)

完整的示例代码为

yourTextView.setTransformationMethod(new PasswordTransformationMethod());

隐藏密码.要显示密码,您可以设置现有的转换方法之一,或实现一个空的 TransformationMethod 对输入文本不执行任何操作.

to hide the password. To show the password you could set one of the existing transformation methods or implement an empty TransformationMethod that does nothing with the input text.

yourTextView.setTransformationMethod(new DoNothingTransformation());

这篇关于如何在隐藏和查看密码之间切换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆