android获取状态栏高度的方法

页面初始化的时候调用,statusHeight 即为状态栏的高度

Rect localRect = new Rect();

getWindow().getDecorView().getWindowVisibleDisplayFrame(localRect);
statusHeight = localRect.top;
if (0 == statusHeight) {
Class<?> localClass;
try {
localClass = Class.forName("com.android.internal.R$dimen");
Object localObject = null;
int intenger = 0;
localObject = localClass.newInstance();
intenger = Integer.parseInt(localClass
.getField("status_bar_height").get(localObject)
.toString());
statusHeight = this.getResources().getDimensionPixelSize(
intenger);
} catch (Exception e) {
e.printStackTrace();
}
}
阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页