I am trying to show user the typed password in edit text whose input type is text Password.
I implemented gesturelistener over the toggle icon like this-
public boolean onTouch(View view, MotionEvent motionEvent) {
switch (view.getId())
{
case R.id.ivPasswordToggle:
switch ( motionEvent.getAction() ) {
case MotionEvent.ACTION_DOWN:
Toast.makeText(getContext(),"show",Toast.LENGTH_SHORT).show();
etPassword.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
break;
case MotionEvent.ACTION_UP:
etPassword.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD | InputType.TYPE_CLASS_TEXT);
Toast.makeText(getContext(),"hide",Toast.LENGTH_SHORT).show();
break;
}
break;
}
return true;
}
i dont know what is wrong, any help will be appreciated.
Since the Support Library v24.2.0. you can achivie this very easy
What you need to do is just:
Add the design library to your dependecies
Use
TextInputEditText
in conjunction withTextInputLayout
passwordToggleEnabled
attribute will make the password toggle appearIn your root layout don't forget to add
xmlns:app="http://schemas.android.com/apk/res-auto"
You can customize your password toggle by using:
app:passwordToggleDrawable
- Drawable to use as the password input visibility toggle icon.app:passwordToggleTint
- Icon to use for the password input visibility toggle.app:passwordToggleTintMode
- Blending mode used to apply the background tint.More details in TextInputLayout documentation.
Please try this code.
I hope it will work, thanks.
Try the following method. Here, we are setting a compound drawable which when clicked will show or hide the password:
If you don't want any extra bool or dependencies, then
and
that's it!