Android 软键盘与自定义键盘 切换

记录一下工作中遇到的问题

问题:、自定义键盘   完全是用layout的show  hidd  实现的。会与软键盘存在问题,就是软键盘弹出的时候,自定义的布局也在显示,从而导致   上面是自定义键盘   下面是软键盘。

解决:想到监听软键盘的弹出  隐藏 从而控制自定义键盘

使用:buttonBeyondKeyboardLayout((ViewGroup) ((mActivity).getWindow().getDecorView().findViewById(android.R.id.content)));
private void buttonBeyondKeyboardLayout(final View root) {

        mListener = new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {

                final Rect rect = new Rect();
                root.getWindowVisibleDisplayFrame(rect);
                final int screenHeight = root.getRootView().getHeight();
                final int heightDifference = screenHeight - rect.bottom;
                //计算控件
                int[] location = new int[2];
                bottomLayout.getLocationOnScreen(location);
//                LogUtil.e("lishuai----计算得到控件在屏幕中的位置222-----:" + location[1]);
                // 事件为弹出软键盘时,软件盘至少有100px吧 这里100可以替换为软件盘的高度
                if (heightDifference > screenHeight / 3) {
//                    LogUtil.e("lishuai----出---显示软键盘");
                    //显示软键盘  判断是否两个键盘都在显示
                    if (location[1] < screenHeight / 3) {
                        if (bottomLayout.getVisibility() == View.VISIBLE) {
                            //显示软键盘
                            if (!mCanKeyBoard) {
                                InputMethodUtil.hideSystemKeyboardByHideNotAlways(mActivity);
                                mCanKeyBoard = true;
                            } else {
                                keyboardlines.setVisibility(View.VISIBLE);
                                textlines.setVisibility(View.GONE);
                                imagelines.setVisibility(View.GONE);
                                reportlines.setVisibility(View.GONE);
                                bottomLayout.setVisibility(View.GONE);
                                mCanKeyBoard = false;
                            }

                        }
                    } else {
                        mCanKeyBoard = false;
                    }


                } else {
                    // 软键盘隐藏进行还原
//                    LogUtil.e("lishuai----收");
                }
            }
        };
        mTreeObserver = root.getViewTreeObserver();
        mTreeObserver.addOnGlobalLayoutListener(mListener);
    }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值