状态栏
状态栏样式
方式一(推荐)
//获取状态栏的高度
private int getStatusBarHeight(Activity activity) {
int resourceId = activity.getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
return activity.getResources().getDimensionPixelSize(resourceId);
}
return 0;
}
方式二
private int getStatusBarHeight() {
int statusBarHeight = 0;
try {
Class<?> c = Class.forName("com.android.internal.R$dimen");
Object object = c.newInstance();
Field field = c.getField("status_bar_height");
int x = (Integer) field.get(object);
statusBarHeight = getResources().getDimensionPixelSize(x);
} catch (Exception e) {
e.printStackTrace();
}
return statusBarHeight;
}
网友评论