简体   繁体   中英

How do I detect if a user has touched any part of the screen other than the inside of an EditText?

I am guessing this means making the whole screen touchable. How exactly is that done?

and secondly calculating if an X,Y is within the EditText.

override the onTouchEvent in the activity you want to implement this....and get the X, Y co-ordinates using event.getX() and event.getY()

   @Override
    public boolean onTouchEvent(MotionEvent event) {
        int x = (int)event.getX();
        int y = (int)event.getY();
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
            case MotionEvent.ACTION_MOVE:
            case MotionEvent.ACTION_UP:
        }
    return false;
    }

but i suggest you must search thoroughly before posting a question.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM