当我在可编辑范围外点击时,如何使键盘消失(通过代码)就像在android中的文本框一样?
答案 0 :(得分:0)
public boolean OutsideTouchEvent(MotionEvent m_event) {
View v = getCurrentFocus();
boolean value = super.dispatchTouchEvent(m_event);
View w = getCurrentFocus();
int scrcoords[] = new int[2];
w.getLocationOnScreen(scrcoords);
float x = m_event.getRawX() + w.getLeft() - scrcoords[0];
float y = m_event.getRawY() + w.getTop() - scrcoords[1];
if (m_event.getAction() == MotionEvent.ACTION_UP && (x < w.getLeft() || x >= w.getRight() || y < w.getTop() || y > w.getBottom()) ) {
InputMethodManager inputMethodManager = (InputMethodManager) YourActivity.this.getSystemService(Activity.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(YourActivity.this.getCurrentFocus().getWindowToken(), 0);
}
return value;
}