public static void hideSoftInputView(Activity activity) { InputMethodManager manager = (InputMethodManager)activity.getSystemService(Context.INPUT_METHOD_SERVICE); if(activity.getWindow().getAttributes().softInputMode != 2 && activity.getCurrentFocus() != null) { manager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 2); } }