I use this method to remove the keyboard from the edit text:
public static void hideKeyboard(Activity activity, IBinder binder) { if (activity != null) { InputMethodManager inputManager = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE); if (binder != null && inputManager != null) { inputManager.hideSoftInputFromWindow(binder, 0);
And this method for removing the keyboard from activity (does not work in some cases - for example, when the edittext that the keyboard is attached to has lost focus, this will not work. But for other situations it works fine, and you do not need to take care of the element that holds keyboard)
public static void hideKeyboard(Activity activity) { if (activity != null) { InputMethodManager inputManager = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE); if (activity.getCurrentFocus() != null && inputManager != null) { inputManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0); inputManager.showSoftInputFromInputMethod(activity.getCurrentFocus().getWindowToken(), 0); } } }
Anton Kizema Jul 10 '15 at 10:16 2015-07-10 10:16
source share