Show the password with EditText

前端 未结 12 896
旧时难觅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:27

    I think you are using the wrong function. I make that way and work perfectly:

    passwordEditView = (EditText) rootView.findViewById(R.id.password);
    final CheckBox showPasswordCheckBox = (CheckBox) rootView.findViewById(R.id.checkbox);
    showPasswordCheckBox.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (showPasswordCheckBox.isChecked()){
                passwordEditView.setTransformationMethod(null);
            }else{
                passwordEditView.setTransformationMethod(new PasswordTransformationMethod());
           }
        }
    });
    

提交回复
热议问题