0

I would like to change the input type in a password field to show or hide the password.

An example is the Facebook login where the password field has an eye icon that shows the password when I type in it.

How can I achieve that in Android?

gobernador
  • 5,659
  • 3
  • 32
  • 51
  • 1
    See here: http://stackoverflow.com/questions/3685790/android-how-to-switch-between-hide-and-view-password – Panda Feb 17 '16 at 21:30

1 Answers1

0
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_Password);
    final EditText password = (EditText)findViewById(R.id.editText_Password);
    ((CheckBox)findViewById(R.id.checkBox_ShowPassword))
            .setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            password.setInputType(isChecked ? 
                    InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD : 
                    InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
        }
    });
}