2

How can i make the keyboard disappears (by code) when i click outside the editable are like textbox in android ?

Adham
  • 63,550
  • 98
  • 229
  • 344
  • 1
    On 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 Jan 09 '11 at 21:50
  • Check this link http://stackoverflow.com/questions/4165414/how-to-hide-soft-keyboard-on-android-after-clicking-outside-edittext – GSree Jan 09 '11 at 23:54

1 Answers1

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;

}
Ebin Sebastian
  • 1,291
  • 1
  • 13
  • 15