使用 getCurrentFocus 或 getSystemService

我想隐藏键盘:


View view = this.getCurrentFocus();


if (view != null) {

    InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);

        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);

        }

    }

});

现在我的问题,是getCurrentFocus和getSystemService是红色,它说:


Cannot resolve method getCurrentFocus() / getSystemService()

我究竟做错了什么?


谢谢你的帮助!


慕的地10843
浏览 239回答 1
1回答

米琪卡哇伊

这getSystemService应该有一个context之前:InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE); // or context或getActivity()或类似的代码来获取上下文。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java