您的位置:首页 > 移动开发 > Android开发

android 密码显示与隐藏的切换

2016-03-05 11:25 295 查看
经常看到密码的显示与隐藏,之前一直没有想过。本来以为是通过InputType控制的呢,后来发现不对,所以整理一下,其实关键点就一个地方。写这个就权当做个笔记吧:

TransformationMethod type= edPassword.getTransformationMethod();
if (PasswordTransformationMethod.getInstance().equals(type)){
edPassword.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
img_userpsd_show.setImageResource(R.drawable.chebao_3_psdshow);
}else {
edPassword.setTransformationMethod(PasswordTransformationMethod.getInstance());
//                   edPassword.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
img_userpsd_show.setImageResource(R.drawable.chebao_3_psdhidden);
}


关键点解释:

密码显示:

edPassword.setTransformationMethod(HideReturnsTransformationMethod.getInstance());


密码隐藏:

edPassword.setTransformationMethod(PasswordTransformationMethod.getInstance());
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: