1
Implement the following method:
private void hideSoftKeyboard() {
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(getView().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}
When you want to close the keyboard just use:
hideSoftKeyboard();
If the method is implemented in a Fragment instead of
getSystemService(Activity.INPUT_METHOD_SERVICE)
use
getActivity().getSystemService(Activity.INPUT_METHOD_SERVICE)