经常看到密码的显示与隐藏,之前一直没有想过。本来以为是通过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());