Android 用反射方式获取状态条高度
private static int getStatusBarHeight(Context context) {
Class<?> c;
Object obj;
Field field;
int x;
try {
c = Class.forName("com.android.internal.R$dimen");
obj = c.newInstance();
field = c.getField("status_bar_height");
x = Integer.parseInt(field.get(obj).toString());
return context.getResources().getDimensionPixelSize(x);
} catch (Exception e1) {
Log.e("get status bar height fail", "");
e1.printStackTrace();
return -1;
}
}