开发者

MotionEvent.ACTION_UP on Textview

开发者 https://www.devze.com 2023-03-24 16:46 出处:网络
My TextView does not support the MotionEvent.Action_UP. I only get 0 on event.getAction. But the same Code works perfekt for a ImageButton.

My TextView does not support the MotionEvent.Action_UP. I only get 0 on event.getAction.

But the same Code works perfekt for a ImageButton.

Doesn't a Textview support the MotionEvent.Action_UP?

   textView.setOnTouchListener(new OnTouchListener() {    
                @Override
                public boolean onTouch(final View v, final MotionEvent event) {
                    Log.v("tag","textView"+event.getAction());
                    if (event.getAction() == MotionEvent.ACTION_DOWN) {
                        Log.v("tag","textViewmousedown");
                    } else if(event.getAction() == MotionEvent.ACTION_UP) {
                        //This gets never called
                        Log.v("tag","textViewmouseup");
                        if (standardButtonClickListener !=开发者_运维百科 null) {
                            standardButtonClickListener.onStandardButtonClick(v);
                        }
                    }
                    return false;
                }
            });


You have to return true instead of false in your onTouch method. This way, further events will be delivered to your listener.


Don't forget MotionEvent.ACTION_CANCEL

 @Override
    public boolean onTouch(final View view, final MotionEvent motionEvent) {

        if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
                setColorFilter(Color.argb(155, 185, 185, 185));
        }
        else if (motionEvent.getAction() == MotionEvent.ACTION_UP || motionEvent.getAction() == MotionEvent.ACTION_CANCEL) {
                setColorFilter(Color.argb(0, 185, 185, 185));

        }
        return false;
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号