2

I am trying to hide my soft keyboard from an InputMethodService, and it isn't working. Here is the code I am using in my onFinishInput() method:

InputMethodManager im = (InputMethodManager)
context.getSystemService(Context.INPUT_METHOD_SERVICE);
im.hideSoftInputFromWindow(mInputView.getWindowToken(), 0);

Any ideas?

coder
  • 10,172
  • 17
  • 67
  • 122
  • Maybe duplicate : http://stackoverflow.com/questions/1109022/how-to-close-hide-the-android-soft-keyboard – Michaël Dec 14 '11 at 15:26
  • 1
    The difference is I am calling this from an InputMethodService - not an Activity – coder Dec 14 '11 at 15:29
  • @hsnepen, huh? You are calling hideSoftInputFromWindow ON the InputMethodManager. This call, presumably, is taking place inside of an Activity. Oh, and this is a duplicate for sure: http://stackoverflow.com/questions/1109022/how-to-close-hide-the-android-soft-keyboard – LuxuryMode Dec 14 '11 at 15:37
  • I am extending the InputMethodService - not an Activity. This is NOT being called from inside of an Activity. It is being called inside an extension of a Service. – coder Dec 14 '11 at 15:44

2 Answers2

6

The following has worked for me:

requestHideSelf(0);

mInputView.closing();
Rubens
  • 13,469
  • 10
  • 56
  • 90
user1925007
  • 79
  • 1
  • 2
  • 1
    Works great. Ignore the mInputView.closing(); requestHideSelf(0); does it alone. – WalterF Aug 23 '17 at 14:53
  • from https://developer.android.com/reference/android/inputmethodservice/InputMethodService.html#requestHideSelf(int) – Suragch Jun 05 '18 at 02:44
0

You can hide soft keyboard from manifest , Try this one:

android:windowSoftInputMode="stateHidden"
iSun
  • 1,526
  • 6
  • 26
  • 53
  • This would not be the answer to hide the keyboard from an `InputMethodService`. This is what you would do in an Activity. – Suragch Jun 05 '18 at 02:33