3

I am trying to use the following code to hide the soft keyboard when a user clicks a button:

InputMethodManager imm = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE);
    imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);

But I get an error:

InputMethodManager not defined

I am thinking I need to add an import statement? If so does anyone know what? Or how can I fix the issue?

Suragch
  • 484,302
  • 314
  • 1,365
  • 1,393
Jay
  • 89
  • 1
  • 10

1 Answers1

5

InputMethodManager is in package android.view.inputmethod, so you need to add

import android.view.inputmethod.InputMethodManager;

to your class.

Aleks G
  • 56,435
  • 29
  • 168
  • 265