private int getStatusBarheight() {
try {
Class<?> clazz = Class.forName("com.android.internal.R$dimen");
Object obj = clazz.newInstance();
Field field = clazz.getField("status_bar_height");
int resId = Integer.parseInt(field.get(obj).toString());
int height = getResources().getDimensionPixelSize(resId);
return height;
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
return 0;
}
获取status bar的高度
最新推荐文章于 2021-05-25 17:12:11 发布