Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

InputMethodManager keyword is not defined in android app

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?

like image 865
Jay Avatar asked Jun 20 '26 20:06

Jay


1 Answers

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

import android.view.inputmethod.InputMethodManager;

to your class.

like image 97
Aleks G Avatar answered Jun 22 '26 09:06

Aleks G



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!