-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEditText
More file actions
27 lines (24 loc) · 1.08 KB
/
Copy pathEditText
File metadata and controls
27 lines (24 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/**
* EditText 失去焦点隐藏输入法
*/
public boolean dispatchTouchEvent(MotionEvent event) {
View v = getCurrentFocus();
boolean ret = super.dispatchTouchEvent(event);
if (v instanceof EditText) {
View currentFocus = getCurrentFocus();
int screenCoords[] = new int[2];
currentFocus.getLocationOnScreen(screenCoords);
float x = event.getRawX() + currentFocus.getLeft() - screenCoords[0];
float y = event.getRawY() + currentFocus.getTop() - screenCoords[1];
if (event.getAction() == MotionEvent.ACTION_UP
&& (x < currentFocus.getLeft() ||
x >= currentFocus.getRight() ||
y < currentFocus.getTop() ||
y > currentFocus.getBottom())) {
InputMethodManager imm =
(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getWindow().getCurrentFocus().getWindowToken(), 0);
}
}
return ret;
}