I have a doubt regarding the layout, I want to generate an activity, where the password EditText appears an eye, which reveals what is written, something like this:
There are many ways to do this, but from what I saw in your image you want to press a button and display them, this function should suffice, where button is the button with the eye icon. And edittext where you write your password.
button.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
switch ( event.getAction() ) {
case MotionEvent.ACTION_DOWN:
editText.setInputType(InputType.TYPE_CLASS_TEXT);
break;
case MotionEvent.ACTION_UP:
editText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
break;
}
return true;
}
});
Another way is to use that PasswordEditText library that has been updated for 24.2.0 and you can assign the icon with visible and non-visible state, that is, with the eye, eye crossed out.
As the friend Webserveis comments , it can already be done in a simple and native way with the TextInputLayout using the Android support library 24.2.0. In your layout:
There are many ways to do this, but from what I saw in your image you want to press a button and display them, this function should suffice, where button is the button with the eye icon. And edittext where you write your password.
I found the following to see if it works for you:
With the new version of the support library
Android support library 24.2.0
it seems that it can be done in this way:Official TextInputLayout Documentation
Extracted from Android password visibility toggle
Another way is to use that PasswordEditText library that has been updated for 24.2.0 and you can assign the icon with visible and non-visible state, that is, with the eye, eye crossed out.
As the friend Webserveis comments , it can already be done in a simple and native way with the TextInputLayout using the Android support library 24.2.0. In your layout:
By setting the inputType to textPassword , it will come out automatically.