按钮单击隐藏键盘

F. *_*lha 0 android

我有一个meme creator应用程序,我有两个文本字段和一个按钮,我想按下按钮来隐藏键盘,这可能吗?

Jee*_*han 7

public void dismissKeyboard(Activity activity) {
        InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
        if (null != activity.getCurrentFocus())
            imm.hideSoftInputFromWindow(activity.getCurrentFocus()
                .getApplicationWindowToken(), 0);
    }
Run Code Online (Sandbox Code Playgroud)

活动必须传递给此方法,键盘将被解雇.