效果图
这里的处理都是Android5.0以上的。
修改状态栏颜色
1 | Window window = activity.getWindow(); |
隐藏状态栏
- 法一
1
2
3Window window = activity.getWindow();
View decorView = window.getDecorView();
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN); - 法二
1
2Window window = activity.getWindow();
window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN); 半透明状态栏
1
2Window window = activity.getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
全透明状态栏实现沉浸式
1 | Window window = activity.getWindow(); |
修改状态栏字体颜色
- 设置状态栏图标和文字颜色为黑色
1
2Window window = activity.getWindow();
window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); - 设置状态栏图标和文字颜色为白色参考大大博客
1
window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN|View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
https://www.cnblogs.com/ldq2016/p/8353190.html
https://www.jianshu.com/p/31c4b324894e