Edit text Password Toggle Android

后端 未结 6 2021
滥情空心
滥情空心 2020-12-25 12:31

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-

<         


        
6条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-25 13:29

    Please try this code.

    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.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
                            break;
                        case MotionEvent.ACTION_UP:
                             etPassword.setTransformationMethod(PasswordTransformationMethod.getInstance());
                            Toast.makeText(getContext(),"hide",Toast.LENGTH_SHORT).show();
                            break;
                    }
                    break;
            }
            return true;
        }
    

    I hope it will work, thanks.

提交回复
热议问题