How to close the keyboard?

1

When I step into this fragment with the keyboard already open, it remains open, what breaks my layout, how to hide it, or not to open it?

    
asked by anonymous 25.11.2017 / 16:46

1 answer

3

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)
    
25.11.2017 / 16:58