Hiding the soft keyboard is pain.
I use some methods based on having an EditText which gets focus, but in my current app the keyboard keeps popping up at some point where a new fragment is loaded.
I have a method in my helper class, but it does not work for me:
//Hide keyboard
public static void hideSoftKeyboard(Activity activity) {
activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
}
Do something like this pass any edittext id of that activity..it will work for that activty
public static void hideSoftKeyboard(Activity activity, EditText editText) {
InputMethodManager imm = (InputMethodManager) activity.getSystemService(
Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
}