为了账号安全,请及时绑定邮箱和手机立即绑定

使用 getCurrentFocus 或 getSystemService

使用 getCurrentFocus 或 getSystemService

慕的地10843 2021-10-20 14:47:02
我想隐藏键盘: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()我究竟做错了什么?谢谢你的帮助!
查看完整描述

1 回答

?
米琪卡哇伊

TA贡献1998条经验 获得超6个赞

getSystemService应该有一个context之前:

InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE); // or context

getActivity()或类似的代码来获取上下文。


查看完整回答
反对 回复 2021-10-20
  • 1 回答
  • 0 关注
  • 238 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信