1、通过调用CheckBox的setOnCheckedChangeListener方法
2、
EditText
setTransformationMethod 方法,
显示输入的密码:HideReturnsTransformationMethod.getInstance()
隐藏输入的密码:PasswordTransformationMethod.getInstance()
private void initView() {
ed_pwd=(EditText) findViewById(R.id.pwd_ed);
vb_pwd=(CheckBox) findViewById(R.id.visibility_pwd_cbox);
vb_pwd.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
if(vb_pwd.isChecked()){
ed_pwd.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
}else{
ed_pwd.setTransformationMethod(PasswordTransformationMethod.getInstance());
}
}
});
}