美文网首页
监听软键盘显示或隐藏

监听软键盘显示或隐藏

作者: Thor_果冻 | 来源:发表于2018-12-29 15:54 被阅读0次

监听软键盘显示或隐藏

cl是editText的父布局
cl.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                Rect r = new Rect();
                cl.getWindowVisibleDisplayFrame(r);
                int screenHeight = cl.getRootView()
                        .getHeight();
                int heightDifference = screenHeight - (r.bottom);
                CommonUtil.debug("123===", "--高度变化-->>>>>>>"+heightDifference);
                if (heightDifference > 400) {
                    //软键盘显示
                    mIsShoKeyborad = true;
                } else {
                    //软键盘隐藏
                    if (!mIsShoKeyborad) {
                        return;
                    }
                    mIsShoKeyborad = false;
                    if (mUseMaxMet.hasFocus()) {
                        CommonUtil.debug("123===", "---->>>>>>>1");
                        CommonUtil.closeKeyboard(MemberCheckOutActivity.this, mUseMaxMet);
                        //处理逻辑...
                    }
                }
            }
        });

相关文章

网友评论

      本文标题:监听软键盘显示或隐藏

      本文链接:https://www.haomeiwen.com/subject/cucplqtx.html