码迷,mamicode.com
首页 > 其他好文 > 详细

沉浸式状态栏使用记录

时间:2017-12-19 19:27:57      阅读:179      评论:0      收藏:0      [点我收藏+]

标签:log   col   black   blog   build   uil   layout   背景   默认   

//状态栏类型
public static final int STATUSBAR_TYPE_TRANSPARENT_WHITE = 1; //状态栏类型为透明底部,白色字体图标
public static final int STATUSBAR_TYPE_WHITE_BLACK = 2; //状态栏类型为白色底部,黑色字体图标
public static void setStatusBar(Activity pActivity, int pStatusbarType) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
//5.x开始需要把颜色设置透明,否则导航栏会呈现系统默认的浅灰色
Window window = pActivity.getWindow();
View decorView = window.getDecorView();
//两个 flag 要结合使用,表示让应用的主体内容占用系统状态栏的空间
int option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
if (pStatusbarType == STATUSBAR_TYPE_WHITE_BLACK) {
option |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
}
decorView.setSystemUiVisibility(option);
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);

if (pStatusbarType == STATUSBAR_TYPE_WHITE_BLACK) {
//背景
window.setStatusBarColor(Color.WHITE);
} else if (pStatusbarType == STATUSBAR_TYPE_TRANSPARENT_WHITE) {
//背景
window.setStatusBarColor(Color.TRANSPARENT);
}
//底部导航栏颜色
// window.setNavigationBarColor(Color.TRANSPARENT);
// window.setNavigationBarColor(ContextCompat.getColor(activity, R.color.black));
} else {
//以下这种情况没有测试过
/* if (pStatusbarType == UtilsKey.STATUSBAR_TYPE_WHITE_BLACK) {
setStatusBar2(pActivity);
} else if (pStatusbarType == UtilsKey.STATUSBAR_TYPE_TRANSPARENT_WHITE) {*/
Window window = pActivity.getWindow();
WindowManager.LayoutParams attributes = window.getAttributes();
int flagTranslucentStatus = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
attributes.flags |= flagTranslucentStatus;
/*int flagTranslucentNavigation = WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION;
attributes.flags |= flagTranslucentNavigation;*/
window.setAttributes(attributes);
// }
}
}
}

public static void setStatusBar2(Activity pActivity) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
pActivity.getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
pActivity.getWindow().setStatusBarColor(Color.WHITE);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
pActivity.getWindow().setStatusBarColor(ContextCompat.getColor(pActivity, R.color.translucent));
}
pActivity.getWindow().setNavigationBarColor(ContextCompat.getColor(pActivity, R.color.black));
}
}

沉浸式状态栏使用记录

标签:log   col   black   blog   build   uil   layout   背景   默认   

原文地址:http://www.cnblogs.com/andy-songwei/p/8066161.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!