直接上代码:
RelativeLayout rootLayout; //根布局
rootLayout = (RelativeLayout) this.findViewById(R.id.rootLayout);
rootLayout.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
// TODO Auto-generated method stub
Rect r = new Rect();
rootLayout.getWindowVisibleDisplayFrame(r);
//r.top 是状态栏高度
int screenHeight = rootLayout.getRootView().getHeight();
int softHeight = screenHeight - (r.bottom - r.top);
Log.e("Keyboard Size", "Size: " + softHeight);
//boolean visible = heightDiff > screenHeight / 3;
}
});