How to close the keyboard?

Asked

Viewed 490 times

1

When I step into this Fragment with the keyboard already open, it remains open, which ruins my layout, how to hide it or not open it?

inserir a descrição da imagem aqui

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)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.