/**
* 获取通知栏的高度
* @param activity
* @return
*/
public static int getStatusBarHeight(Activity activity){
Rect rect = new Rect();
activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(rect);
return rect.top;
}
/**
* 获取通知栏(状态栏)的高度
*
* @return statusBarHeight
*/
private int getStatusBarHeight() {
Class<?> clazz;
Object object;
Field field;
int x;
int statusBarHeight = 0;
try {
clazz = Class.forName("com.android.internal.R$dimen");
object = clazz.newInstance();
field = clazz.getField("status_bar_height");
x = Integer.parseInt(field.get(object).toString());
statusBarHeight = getResources().getDimensionPixelSize(x);
} catch (Exception e) {
e.printStackTrace();
}
return statusBarHeight;
}
/** * 获取通知栏的高度 * @param activity * @return */public static int getStatusBarHeight(Activity activity){ Rect rect = new Rect(); activity.getWindow().getDecorView().getWindowVisibleDisplay