热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

安卓编程:沉浸式通知栏(最简单的方式)

首先加入工具类SystemBarTintManager.java下载后加入到包中在onCreate中添加代码if(Build.VERSION.SDK_INTBuild.VERSI

首先加入工具类

SystemBarTintManager.java
下载后加入到包中

在onCreate中添加代码

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
setTranslucentStatus(true);
SystemBarTintManager tintManager = new SystemBarTintManager(this);
tintManager.setStatusBarTintEnabled(true);
tintManager.setStatusBarTintResource(R.color.blue500);//这里调用需要的通知栏颜色
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);

}

在class中添加代码

@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);
}

6.0小米真机上效果

《安卓编程:沉浸式通知栏(最简单的方式)》

4.4模拟器上效果

《安卓编程:沉浸式通知栏(最简单的方式)》

如果有帮助或者喜欢,请点击下面的喜欢,谢谢ヽ(✿゚▽゚)ノ!


推荐阅读
author-avatar
端庄的张佳迎
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有