2013年9月2日星期一

判断statusbar是否存在

private boolean checkStatusbar(){
   Rect rect=new Rect();
   getWindow().getDecorView().getWindowVisibleDisplayFrame(rect);
   //屏幕高度还有别的办法得到,不赘述
   return (rect.bottom-rect.top)
           ==getResources().getDisplayMetrics().heightPixels;
}

另一种计算一般statusbar高度的方法(固定值,不是实时的高度):
(参考http://mrtn.me/blog/2012/03/17/get-the-height-of-the-status-bar-in-android/)
private int getStatusBarHeight() {
   int result = 0;
   int resourceId = getResources()
           .getIdentifier("status_bar_height", "dimen", "android");
   if (resourceId > 0) {
         result = getResources().getDimensionPixelSize(resourceId);
   }
 return result;
}