美文网首页
监听软键盘关闭显示

监听软键盘关闭显示

作者: middle2021 | 来源:发表于2016-10-12 15:13 被阅读32次

通过监听页面的根view的onLayoutChange方法,比较bottom和oldBottom的值。
bottom>oldBottom 表示布局下移,键盘收起,反之键盘弹出

view.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
            @Override
            public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, 
            int oldTop, int oldRight, int oldBottom) {
                KLog.i("bottom " + bottom + " oldBottom " + oldBottom);
                if (bottom < oldBottom) {
                    // keyboard show
                } else {
                   // keyboard hide
                }
            }
        });

相关文章

网友评论

      本文标题:监听软键盘关闭显示

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