Android 4.0.3 之后传统方法获取状态栏高度都是0:
- Rect frame = new Rect();
- getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
- int statusBarHeight = frame.top;
网上牛人处看来的,可以解决这个问题:
- Class<?> c = null;
- Object obj = null;
- Field field = null;
- int x = 0, sbar = 0;
- 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());
- sbar = getResources().getDimensionPixelSize(x);
- } catch (Exception e1) {
- loge("get status bar height fail");
- e1.printStackTrace();
- }
出处: http://www.zhaolongedu.com/a/Androidkaifa/2011/1220/364.html