您的位置:首页 > 移动开发 > Android开发

Android 获取状态栏高度

2015-09-11 12:40 555 查看
Rect frame = new Rect();   
getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);   
int statusBarHeight = frame.top;  
有些时候这个方法可能是0,用下面的方法

在源码程序中获取状态栏高度代码:height= getResources().getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);class c = Class.forName("com.android.internal.R$dimen");
Object obj = c.newInstance();
Field field = c.getField("status_bar_height");
int x = Integer.parseInt(field.get(obj).toString());
int y = getResources().getDimensionPixelSize(x);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: