0

How should I use InputMethodManager.hideSoftInputFromWindow(IBinder, int) if I want to dismiss an open keyboard?

In particular, for the first argument I see lots of suggestions to pass a view's token like this:

InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
View view = getCurrentFocus();
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);

In particular, I'm confused about getCurrentFocus() and the view that it returns. Can I pass any view's token? Why is view.getWindowToken() suggested? Why is it even necessary to pass a view's token?

dmc7z
  • 1
  • 1
  • 1
  • It's confusing but the accepted answer in this [post](https://stackoverflow.com/questions/1109022/how-do-you-close-hide-the-android-soft-keyboard-programmatically) pretty much sums it up. – javdromero Jun 06 '21 at 05:14

0 Answers0