3

I want to know how to hide and (after certain action) then show the Android Soft keyboard. This is fairly easy with API Level 24, however I am targeting API level 23.

Following is my code which works for API Level 24:

// to hide
getSoftKeyboardController().setShowMode(SHOW_MODE_HIDDEN);

// to show
getSoftKeyboardController().setShowMode(SHOW_MODE_AUTO);

How do I do same with API Level 23?

avi
  • 9,292
  • 11
  • 47
  • 84

1 Answers1

-3

Hide keyboard

public static void hideKeyboardFrom(Context context, View view) {
      InputMethodManager imm = (InputMethodManager) context.getSystemService(Activity.INPUT_METHOD_SERVICE);
      imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
Tom Solid
  • 2,226
  • 1
  • 13
  • 32
Narendra Sorathiya
  • 3,770
  • 2
  • 34
  • 37
  • I am within an accessibility service, so `this.getCurrentFocus` is not available – avi Mar 07 '17 at 17:38
  • What do I pass for `view`? I do not have any `View` since its within an accessibility service. – avi Mar 07 '17 at 17:42
  • 2
    this answer is not right and wouldn't work. Please delete it. – avi Mar 12 '17 at 07:52
  • 1
    Answer needs supporting information Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](https://stackoverflow.com/help/how-to-answer). – moken Jul 22 '23 at 09:21