监听软键盘关闭显示

2016-10-12  本文已影响32人  middle2021

通过监听页面的根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
                }
            }
        });
上一篇 下一篇

猜你喜欢

热点阅读