我用一个EditText输入密码。 而一个复选框以显示密码或者没有。 以下功能部件:
I use an EditText to enter password. And a CheckBox to show password or not. Below function is the part:
public void ShowPassword() {
if(cb.isChecked()) {
password.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
}
else {
password.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);
}
}
在对其进行检查时,显示的密码。 但是,未选中时,它显示出来的明星。 如何修改它以显示明星,而CB没有被选中?
When it checked, it show password. But when it not checked, it does show stars. How to modify it to show star while the cb is not checked?
我不知道具体的细节,但是这code应该工作:
I don't know exactly the specifics, but this code should work:
checkbox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(!isChecked) {
password.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);
} else {
password.setInputType(129);
}
}
});
129
是输入型组设置 Android的时候:inputType =textPassword
编辑:
中提到的@ user370305的回答, 129
是按位或操作时,您
as mentioned in @user370305's answer, 129
is the value of the bitwise or operation when you do
password.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);