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?
InputMethodManager
is in package android.view.inputmethod
, so you need to add
import android.view.inputmethod.InputMethodManager;
to your class.