获得系统状态栏高度(隐藏也能取到非零的值)
private int getStatusBarHeight(Context context) {
double statusBarHeight = Math.ceil(25 * context.getResources().getDisplayMetrics().density);
return (int)statusBarHeight;
}
获得软件状态栏高度(隐藏的状态栏高度返回为0)
private int getStatusBarHeight(Context context) {
int result = 0;
int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
result = context.getResources().getDimensionPixelSize(resourceId);
}
return result;
}
隐藏状态栏(既微信朋友圈状态栏的效果)加在onCreate里面super语句后面
requestWindowFeature(Window.FEATURE_NO_TITLE);
if (getSupportActionBar() != null){
getSupportActionBar().hide();
}//先隐藏标题栏,标题栏在状态栏下面,不隐藏的话光隐藏状态栏是没用的
if (Build.VERSION.SDK_INT >= 21){
View decorView = getWindow().getDecorView();
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
getWindow().setStatusBarColor(Color.TRANSPARENT);
}//隐藏状态栏是安卓5.0后才有的,所以要判断SDK版本大于等于5.0的才行,下面就简单了 直接隐藏设置透明