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

来源:互联网 发布:丽得姿黑面膜淘宝 编辑:程序博客网 时间:2024/04/30 14:12

废话不多说,挺简单,就是之前没有了解过,简单做一下笔记有用到的方便再次使用,直接上图:
这里是隐藏密码状态:
这里写图片描述
显示密码状态:
显示密码状态:
这里关键的是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布局文件特别简单,在这里就不展示了。

0 0
原创粉丝点击