Change to custom icon from eye-icon(default) for hide-show password in android EditText

后端 未结 9 999
时光取名叫无心
时光取名叫无心 2020-12-25 15:14

I want to change/display different icons for show password in android edittext. I am using following code to display icon.



        
9条回答
  •  情书的邮戳
    2020-12-25 15:49

    In your Xml Make a RelativeLayout with TextInputLayout and Imageview

     
    
                
    
                    
    
                
    
                
    
            
    

    And in your Activity add onTouch() method for showing and hidding your password.

        ImageView imagepass = (ImageView) findViewById(R.id.imagepassword);
        imagepass .setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
    
                switch (motionEvent.getAction()) {
                    case MotionEvent.ACTION_DOWN:
                        editpass.setInputType(InputType.TYPE_CLASS_TEXT);
                        break;
                    case MotionEvent.ACTION_UP:
                        editpass.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
                        break;
                }
                return true;
            }
        });
    

提交回复
热议问题