Hide Soft Keyboard
Asked Answered
A

1

11

I need to be able to hide the soft keyboard in response to clicking a button. I have seen numerous posts on this subject and it seems that the solution is to use the InputMethodManager, but I have been unable to get it to work for me. Supposedly the following will hide the soft keyboard:

  InputMethodManager inputManager = (InputMethodManager) 
         getSystemService(INPUT_METHOD_SERVICE);

  inputManager.hideSoftInputFromInputMethod(editView.getWindowToken(), 0);

However, this is not working for me (can any suggest why?), and even if it did, I want to be able to hide the keyboard regardless of what view has the input, and I may not know what view that is.

I found that the call:

inputManager.toggleSoftInput(0, 0);

will hide the keyboard if it is currently being shown. Unfortunately it will also show it if it is currently hidden. So for this to work for me, I would need a way to determine whether it is currently visible.

Any ideas?

Thanks

Anibalanica answered 4/10, 2010 at 19:14 Comment(0)
B
23

You might want to try:

InputMethodManager inputManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(editView.getWindowToken(), 0);
Broaddus answered 4/10, 2010 at 20:30 Comment(1)
Well, duh! I guess it would help if I called the correct function. Thanks.Anibalanica

© 2022 - 2024 — McMap. All rights reserved.