android软键盘的隐藏问题

来源:互联网 发布:淘宝怎么报名参加双11 编辑:程序博客网 时间:2024/06/12 01:39

1) 如果一定要隐藏使用如下方法:

            InputMethodManager imm = (InputMethodManager)

                                                           leftBtn.getContext().getSystemService(INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(leftBtn.getWindowToken(),InputMethodManager.HIDE_NOT_ALWAYS);

其中LeftBtn是该布局中某个控件,hideSoftInputFromWindow()方法就是隐藏软键盘。

 

 

2) 如果需要切换软键盘,就是原来没有弹出软件盘时去显示软键盘;原来有软键盘弹出时就去隐藏软件盘,代码如下:

            InputMethodManager imm=(InputMethodManager)

                                                        leftBtn.getContext().getSystemService(INPUT_METHOD_SERVICE);

            imm.toggleSoftInput(1, InputMethodManager.HIDE_NOT_ALWAYS);

原创粉丝点击