How to hide keyboard on outside tap for edittext, in android.

How to hide keyboard on outside tap for  edittext, in android.?
Last updated:2/27/2015 5:53:21 AM

1 Answers

Jayden Bell
Jayden Bell

On your activity you have need to add touch method like this :


      @Override
      public boolean onTouchEvent(MotionEvent event) {
            // TODO Auto-generated method stub
 
            InputMethodManager inputManager =(InputMethodManager) getApplicationContext()
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
 
            inputManager.hideSoftInputFromWindow(MainActivity.this.getCurrentFocus().getWindowToken(),
 
            InputMethodManager.HIDE_NOT_ALWAYS);
 
            return super.onTouchEvent(event);
      } 

Answer