Android -- 状态栏高度

干货

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();
}

 

下面代码不要放在onCreate中,否则获取状态栏高度为0

Rect frame = new Rect();
getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);

int statusBarHeight = frame.top;

我是天王盖地虎的分割线

posted @ 2015-05-02 00:07  我爱物联网  阅读(706)  评论(0编辑  收藏  举报
AmazingCounters.com