Android PopupWindow与软键盘的遮挡问题

来源:互联网 发布:淘宝lee官方旗舰店 编辑:程序博客网 时间:2024/05/17 23:15

PopupWindow含有输入框时,点击输入框,软键盘可能会挡住PopupWindow,而我们希望的是软键盘能够把PopupWindow给顶上去。

设置 popupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); 

SOFT_INPUT_ADJUST_RESIZE:            整个Layout重新编排,重新分配多余空间


InputMethodManager m=(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
m.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS); (这个方法可以实现输入法在窗口上切换显示,如果输入法在窗口上已经显示,则隐藏,如果隐藏,则显示输入法到窗口上)


InputMethodManager inputMethodManager = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);            if (inputMethodManager.isActive()) {                inputMethodManager.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);            }            popWindow = new PopupWindow(view, WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);            popWindow.setOutsideTouchable(true);            popWindow.setFocusable(true);            popWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));            popWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);            popWindow.setAnimationStyle(R.style.anim_edit_text_popup);            new Handler().postDelayed(new Runnable() {                @Override                public void run() {                    popWindow.showAtLocation(view, Gravity.BOTTOM, 0, 0);                }            }, 50);



阅读全文
0 0
原创粉丝点击