首先到github上下载SystemBarTint,将里面的SystemBarTintManager.java拷贝出来放到自己的项目中, 在actitvity的onCreate()方法中加入如下代码
代码如下:
|
1
2
3
4
5
6
|
if
(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { setTranslucentStatus(true);
} SystemBarTintManager tintManager =
new SystemBarTintManager(this);
tintManager.setStatusBarTintEnabled(true);
tintManager.setStatusBarTintResource(R.color.statusbar_bg);//通知栏所需颜色 |
下面是设置通知栏的状态
|
1
2
3
4
5
6
7
8
9
10
11
12
|
@TargetApi(19)
private
void setTranslucentStatus(boolean
on) { Window win = getWindow();
WindowManager.LayoutParams winParams = win.getAttributes();
final
int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
if
(on) { winParams.flags |= bits;
} else
{ winParams.flags &= ~bits;
} win.setAttributes(winParams);
} |
这样就可以完美实现沉浸式通知栏的。
注意:
在需要透明状态栏的XML布局文件的Top-level中加上如下属性:
android:fitsSystemWindows="true"
本文介绍如何使用SystemBarTint库实现Android应用的沉浸式通知栏效果,包括代码配置及XML布局设置。
1486

被折叠的 条评论
为什么被折叠?



