InputMethodManager keyword not defined in android app

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

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


But I am getting the error:

InputMethodManager is undefined

I think I need to add an import statement? If so does anyone know what? Or how can I fix the problem?


source to share

1 answer


is in the package android.view.inputmethod

, so you need to add

import android.view.inputmethod.InputMethodManager;


for your class.



All Articles