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

Android笔记:登录显示与隐藏密码

2016-10-22 14:21 363 查看
废话不多说,挺简单,就是之前没有了解过,简单做一下笔记有用到的方便再次使用,直接上图:

这里是隐藏密码状态:



显示密码状态:



这里关键的是EditText的两个属性:

//显示密码
edt_user_psw.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
//隐藏密码
edt_user_psw.setTransformationMethod(PasswordTransformationMethod.getInstance());


下面上一下代码吧,虽然很简单。

is_hide_psw.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
hide_psw = !hide_psw;
if (!hide_psw){
is_hide_psw.setImageResource(R.mipmap.show_psw);
user_name.setText(str_user_name);
user_psw.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
user_name.requestFocus();
}else{
is_hide_psw.setImageResource(R.mipmap.hide_psw);
user_psw.setTransformationMethod(PasswordTransformationMethod.getInstance());
}
}
});


xml布局文件特别简单,在这里就不展示了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  android 密码