Android改变状态栏的背景颜色使其与APP风格一体化
来源:互联网 发布:linux 访问日志 编辑:程序博客网 时间:2024/04/27 18:15
效果图
方法实现
1添加布局属性
首先要在布局文件中加入下面两个属性:
android:clipToPadding="true"
android:fitsSystemWindows="true"
解释一下上面两个布局属性的意思:
android:clipToPadding 定义布局间是否有间距
android:fitsSystemWindows="true" 意思就是设置应用布局时是否考虑系统窗口布局;如果为true,将调整系统窗口布局以适应你自定义的布局。比如系统有状态栏,应用也有状态栏时。看你这个布局代码,恰恰是在定义标题栏样式,所以用到这行代码了。
public static void initSystemBar(Activity activity) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
setTranslucentStatus(activity, true);
}
SystemBarTintManager tintManager = new SystemBarTintManager(activity);
tintManager.setStatusBarTintEnabled(true);
// 使用颜色资源
tintManager.setStatusBarTintResource(R.color.status_color);
}
@TargetApi(19)
private static void setTranslucentStatus(Activity activity, boolean on) {
Window win = activity.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);
}
SystemBarTintManager 是状态栏的管理实例,没有它是不行的,它的开源地址是:https://github.com/hexiaochun/SystemBarTint ,已经封装的非常好了,我们只需要把它下载下来,应用到你的App中即可。
- Android改变状态栏的背景颜色使其与APP风格一体化
- 改变状态栏的颜色使其与APP风格一体化
- 改变状态栏的颜色使其与APP风格一体化
- Android学习第八弹之改变状态栏的颜色使其与APP风格一体化
- Android之改变状态栏的颜色使其与APP风格一体化
- Android学习第八弹之改变状态栏的颜色使其与APP风格一体化
- Android状态栏一体化 (改变状态栏的背景颜色)
- android状态栏一体化(改变状态栏的背景颜色)类似于IOS
- android状态栏一体化(改变状态栏的背景颜色)
- android状态栏一体化(改变状态栏的背景颜色)
- android状态栏一体化(改变状态栏的背景颜色)开源工程推荐
- android状态栏一体化(改变状态栏的背景颜色)开源工程推荐
- android状态栏一体化(改变状态栏的背景颜色)开源工程推荐
- android状态栏一体化(改变状态栏的背景颜色)开源工程推荐
- android状态栏一体化(改变状态栏的背景颜色)开源工程推荐
- android状态栏一体化(改变状态栏的背景颜色)开源工程推荐
- android状态栏一体化(改变状态栏的背景颜色)开源工程推荐
- android状态栏一体化(改变状态栏的背景颜色)开源工程推荐
- NYOJ2 括号配对问题
- 常用的XCode插件
- 位域 大小端
- linux_scandir()
- java 继承
- Android改变状态栏的背景颜色使其与APP风格一体化
- update和repaintde的区别
- MyListView
- 【Android】Uri、UriMatcher、ContentUris详解
- 别以为真懂Openstack: 虚拟机创建的50个步骤和100个知识点(1)
- linux_list_entry()
- 关于网络抓取连接释放不了报错的解决办法
- 复制的web工程为什么不能部署到tomcat
- 分类算法之贝叶斯网络--转自 T2噬菌体