Change to custom icon from eye-icon(default) for hide-show password in android EditText

后端 未结 9 981
时光取名叫无心
时光取名叫无心 2020-12-25 15:14

I want to change/display different icons for show password in android edittext. I am using following code to display icon.



        
9条回答
  •  眼角桃花
    2020-12-25 15:34

    I implement it using text.. that is 'Show' and 'Hide'

    textViewShowPassword.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (textViewShowPassword.getText().toString().equalsIgnoreCase("Show")) {
                    editTextPassword.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
                    textViewShowPassword.setText("Hide");
                    editTextPassword.setSelection(editTextPassword.getText().length());
                } else {
                    textViewShowPassword.setText("Show");
                    editTextPassword.setTransformationMethod(new PasswordTransformationMethod());
                    editTextPassword.setSelection(editTextPassword.getText().length());
                }
    
            }
        });
    

    Hope this help for you..!!

提交回复
热议问题