检测软键盘打开关闭

mainview.getViewTreeObserver().addOnGlobalLayoutListener(()-> {
            Rect r = new Rect();
            //获取当前界面可视部分
            Activity.this.getWindow().getDecorView().getWindowVisibleDisplayFrame(r);
            //此处就是用来获取键盘的高度的, 在键盘没有弹出的时候 此高度为0 键盘弹出的时候为一个正数
            if ((App.screenHeight - r.bottom)> 0) {
                //软键盘已打开
            } else {
              //软键盘已关闭
            }
    });
 

猜你喜欢

转载自blog.csdn.net/csdnwr/article/details/80118831
今日推荐