Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override
- public boolean dispatchTouchEvent(MotionEvent event) {
- View view = getCurrentFocus();
- boolean retnet = super.dispatchTouchEvent(event);
- if (view instanceof EditText) {
- View w = getCurrentFocus();
- int[] scrcoords = new int[2];
- assert w != null;
- w.getLocationOnScreen(scrcoords);
- float x = event.getRawX() + w.getLeft() - scrcoords[0];
- float y = event.getRawY() + w.getTop() - scrcoords[1];
- if (event.getAction() == MotionEvent.ACTION_UP
- && (x < w.getLeft() || x >= w.getRight()
- || y < w.getTop() || y > w.getBottom()) ) {
- InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
- assert imm != null;
- imm.hideSoftInputFromWindow(Objects.requireNonNull(getWindow().getCurrentFocus()).getWindowToken(), 0);
- }
- }
- return retnet;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement