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