Change source image for image view when pressed

前端 未结 16 570
闹比i
闹比i 2020-12-08 19:53

I have a scroll view with lots of image buttons. I want to change the image for an image button when it\'s pressed. The thing is that I want the image to remain until anothe

16条回答
  •  爱一瞬间的悲伤
    2020-12-08 20:47

    Although it's too late to answer. But someones may get help from this answer.

    It's working like charm -

    circularImageView.setOnTouchListener(new View.OnTouchListener() {
    
                public boolean onTouch(View v, MotionEvent event) {
                    switch (event.getAction()) {
                        case MotionEvent.ACTION_DOWN:
                            circularImageView.setImageResource(R.drawable.profile_edit_photo);
                            break;
                        case MotionEvent.ACTION_UP:
                            circularImageView.setImageResource(R.drawable.photo_male_8);
                            break;
                        case MotionEvent.ACTION_MOVE:
                            Log.i("ImageViewEvent", "Action_Move_Called");    
                            break;
                    }
                    return true; // Note: This return value must need to be true if you want to call MotionEvent.ACTION_UP: action. 
                }
    
            });
    

提交回复
热议问题