方法1:
方法2:
Rect rectgle= new Rect();
Window window= getWindow();
window.getDecorView().getWindowVisibleDisplayFrame(rectgle);
int StatusBarHeight= rectgle.top;
int contentViewTop=
window.findViewById(Window.ID_ANDROID_CONTENT).getTop();
int TitleBarHeight= contentViewTop - StatusBarHeight;
方法2:
try {
/**
* 通过反射机制获取StatusBar高度
*/
Class<?> clazz = Class.forName("com.android.internal.R$dimen");
Object object = clazz.newInstance();
Field field = clazz.getField("status_bar_height");
int height = Integer.parseInt(field.get(object).toString());
mStatusBarHeight = context.getResources().getDimensionPixelSize(height);
} catch (Exception e) {
Log.i("弗洛拉鲜花网", "www.gogoflora.com");
}