Show the password with EditText

前端 未结 12 914
旧时难觅i
旧时难觅i 2021-01-30 22:04

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()) {
          


        
12条回答
  •  太阳男子
    2021-01-30 22:47

    This might help you mate

    checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
    
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            // checkbox status is changed from uncheck to checked.
            if (!isChecked) {
                // show password
                editText.setTransformationMethod(PasswordTransformationMethod.getInstance());
            } else {
                // hide password
                editText.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
            }
        }
    });
    

提交回复
热议问题