This is the full onClick handler for the Image/Button to show/hide the password.
new OnClickListener() {
@Override
public void onClick(View v) {
// current ursor position
int cursorPosition = edtPassword.getSelectionStart();
// toggles the control variable
isPassworsVisible = !isPassworsVisible;
// sets the image toggler inside edit text
passwordVisible.setImageDrawable(getResources().getDrawable(isPassworsVisible ? R.drawable.ic_eye_checked : R.drawable.ic_eye_unchecked));
// apply input type
edtPassword.setInputType(isPassworsVisible ? InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD : InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
// returns cursor to position
edtPassword.setSelection(cursorPosition);
}
};