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

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

问题描述

有一个聪明的办法让隐藏和查看密码的用户开关在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 安卓密码来真正的视图会显示点如果将其设置为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.

使用方法<一href="http://developer.android.com/reference/android/widget/TextView.html#setTransformationMethod%28android.text.method.TransformationMethod%29">setTransformationMethod你应该能够改变这种属性,从code。 (免责声明:。如果方法仍然工作时显示的视图后,如果您遇到的问题与该给我留下了评论,我知道我没有测试过)

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.)

全样本code会

yourTextView.setTransformationMethod(new PasswordTransformationMethod());

要隐藏的密码。要显示您可以设置的现有转换方法之一密码或实现一个空的<一个href="http://developer.android.com/reference/android/text/method/TransformationMethod.html">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());

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

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