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?
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?
@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);
}
});
}