@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
if (ev.getAction() == MotionEvent.ACTION_DOWN) {
View v = getCurrentFocus();
if (v instanceof EditText) {
Rect outRect = new Rect();
v.getGlobalVisibleRect(outRect);
if(!outRect.contains((int)ev.getRawX(), (int)ev.getRawY())) {
//v.clearFocus();
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
}
}
}
return super.dispatchTouchEvent(ev);
}
本文介绍了一种在检测到屏幕触摸事件不在EditText控件区域内时隐藏软键盘的方法。通过重写dispatchTouchEvent方法并检查触摸位置来实现这一功能。
3858

被折叠的 条评论
为什么被折叠?



