How can I change the images on an ImageButton in Android when using a OnTouchListener?

前端 未结 2 1545
南方客
南方客 2021-02-19 21:29

I have the following code which creates an ImageButton and plays a sound when clicked:

ImageButton SoundButton1 = (ImageButton)findViewById(R.id.sound1);
SoundBu         


        
2条回答
  •  滥情空心
    2021-02-19 22:03

    SoundButton1.setOnTouchListener(new OnTouchListener() {
    
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN ) {
                mSoundManager.playSound(1);
                btnmode.setImageResource(R.drawable.modeitempressed);
    
            }
             elseif (event.getAction() == MotionEvent.ACTION_UP ) {
                btnmode.setImageResource(R.drawable.modeitemnormal);
    
            }
    
            return false;
        }
    });
    

提交回复
热议问题