2

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

2
  • 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. Commented Jan 9, 2011 at 21:50
  • Check this link stackoverflow.com/questions/4165414/… Commented Jan 9, 2011 at 23:54

1 Answer 1

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;

}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.