安卓软键盘的关闭

来源:互联网 发布:华测rtk如何导出数据 编辑:程序博客网 时间:2024/05/22 13:13

项目中很多时间会遇到当你输入法用完以后,点击事件触发,但是软键盘还一直存在,影响用户的体验。

附上两个关闭软键盘法的方法:

//此方法,如果显示则隐藏,如果隐藏则显示private void hintKbOne() {    InputMethodManager imm = (InputMethodManager)getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);    // 得到InputMethodManager的实例    if (imm.isActive()) {        // 如果开启        imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, InputMethodManager.HIDE_NOT_ALWAYS);    }}//此方法只是关闭软键盘private void hintKbTwo() {    InputMethodManager imm = (InputMethodManager)getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);    if(imm.isActive()&&getActivity().getCurrentFocus()!=null){        if (getActivity().getCurrentFocus().getWindowToken()!=null) {            imm.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);        }    }}

0 0
原创粉丝点击