Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public boolean dispatchTouchEvent(MotionEvent ev) {
- View v = getCurrentFocus();
- if (v != null &&
- (ev.getAction() == MotionEvent.ACTION_UP || ev.getAction() == MotionEvent.ACTION_MOVE) &&
- v instanceof EditText &&
- !v.getClass().getName().startsWith("android.webkit.")) {
- int scrcoords[] = new int[2];
- v.getLocationOnScreen(scrcoords);
- float x = ev.getRawX() + v.getLeft() - scrcoords[0];
- float y = ev.getRawY() + v.getTop() - scrcoords[1];
- if (x < v.getLeft() || x > v.getRight() || y < v.getTop() || y > v.getBottom())
- hideKeyboard(this);
- }
- return super.dispatchTouchEvent(ev);
- }
- public static void hideKeyboard(Activity activity) {
- if (activity != null && activity.getWindow() != null) {
- InputMethodManager imm = (InputMethodManager)activity.getSystemService(Context.INPUT_METHOD_SERVICE);
- assert imm != null;
- imm.hideSoftInputFromWindow(activity.getWindow().getDecorView().getWindowToken(), 0);
- }
- }
Add Comment
Please, Sign In to add comment