parentLayout.getViewTreeObserver().addOnGlobalLayoutListener(
new ViewTreeObserver.OnGlobalLayoutListener() {


@Override
public void onGlobalLayout() {
Rect r = new Rect();
parentLayout.getWindowVisibleDisplayFrame(r);
int screenHeight = parentLayout.getRootView()
.getHeight();
int heightDifference = screenHeight - (r.bottom);
if (heightDifference > 200) {
isKeyBoardVisible = true;
// changeKeyboardHeight(heightDifference);
} else {
isKeyBoardVisible = false;
}
}
});



//parentLayout为布局父控件,因为当软件盘显示和隐藏时当windowSoftInputMode为adjustResize时parentLayout会调

//用onsizechange方法,因此对布局树进行监听可以判读出软件盘的显示与隐藏