【问题标题】:InputMethodManager keyword is not defined in android appandroid 应用程序中未定义 InputMethodManager 关键字
【发布时间】:2012-03-29 17:44:59
【问题描述】:

我正在尝试使用以下代码在用户单击按钮时隐藏软键盘:

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

但我得到一个错误:

InputMethodManager 未定义

我在想我需要添加一个导入语句吗?如果是这样,有人知道吗? 或者我该如何解决这个问题?

【问题讨论】:

    标签: android keyword inputmethodmanager


    【解决方案1】:

    InputMethodManager在包android.view.inputmethod中,所以需要添加

    import android.view.inputmethod.InputMethodManager;
    

    到你的班级。

    【讨论】:

    • 以后,如果你使用eclipse,按(在mac上)Command + Shift + o 来解析所有的导入(在windows上按Control + Shift + o)
    • 更好的帮助...非常感谢!
    猜你喜欢
    • 2017-12-25
    • 2016-04-13
    • 1970-01-01
    • 1970-01-01
    • 2012-09-27
    • 1970-01-01
    • 2019-07-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多