How can i make the keyboard disappears (by code) when i click outside the editable are like textbox in android ?
2
-
1On iOS-devices, clicking outside the view the keyboard is attached to makes it disappear. This is not the case in Android. Here the standard behaviour says that touching the back-button will male the keyboard hide.Jonathan Roth– Jonathan Roth2011-01-09 21:50:00 +00:00Commented Jan 9, 2011 at 21:50
-
Check this link stackoverflow.com/questions/4165414/…GSree– GSree2011-01-09 23:54:43 +00:00Commented Jan 9, 2011 at 23:54
Add a comment
|
1 Answer
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;
}