SystemBarTint的使用(设置半透明状态栏)
来源:互联网 发布:黄河大侠知乎 编辑:程序博客网 时间:2024/06/05 20:14
1.在系统是4.4以上的系统,包括4.4开始可以设置半透明的状态栏了
代码:
- if(VERSION.SDK_INT >= VERSION_CODES.KITKAT) {
- //透明状态栏
- getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
- //透明导航栏
- getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
- }
或者在style中设置主题:
- <style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
- <!-- API 19 theme customizations can go here. -->
- <item name="android:windowTranslucentStatus">true</item>
- <item name="android:windowTranslucentNavigation">true</item>
- </style>
但是设置了这两个属性之后,布局里面的view会自动向上移动,显示在透明状态栏下面(就相当于状态栏外层是framlayout),为了防止这种现象,可以在主题中或者xml设置:
- <item name="android:fitsSystemWindows">true</item>
设置了如上后:
由于使用了Theme.AppCompat.Light.DarkActionBar的主题,默认设置colorPrimaryDark的颜色:
- <item name="colorPrimaryDark">@color/primary_dark_material_dark</item>
如果设置了:
- <item name="colorPrimaryDark">@android:color/transparent</item>
设置了透明后就可以很好的显示了
2.为了兼容地版本,可以使用开源的框架SystemBarTint来实现(这个也只是兼容19以上的版本)
在api 19中是可以通过
(1).
- getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
- android:fitsSystemWindows="true"
(2).
依旧设置:
- getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
如果在actvity的主题中设置:
- android:fitsSystemWindows="true"
(3).如果用SystemBarTint开源类,我们就可以主动改变状态栏的颜色,但是只能设置单色,不能像上面一样随着背景的改变而改变。
1.需要在主题中设置:
- <style name="FullBleedTheme" parent="android:Theme.Holo.Light.NoActionBar.TranslucentDecor">
- <style name="Theme.Holo.Light.NoActionBar.TranslucentDecor">
- <item name="android:windowTranslucentStatus">true</item>
- <item name="android:windowTranslucentNavigation">true</item>
- <item name="android:windowContentOverlay">@null</item>
- </style>
- if(VERSION.SDK_INT >= VERSION_CODES.KITKAT) {
- //透明状态栏
- getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
- //透明导航栏
- getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
- }
2.然后在布局的最外层或者activity的主题中设置:
- android:fitsSystemWindows="true"
3.然后在setContentView(layoutResID)之后调用代码:
- SystemBarTintManager tintManager = new SystemBarTintManager(this);
- tintManager.setStatusBarTintEnabled(true);
- tintManager.setStatusBarTintColor(Color.parseColor("#222231"));
下面再使用如下主题的情况下:
- Theme.AppCompat.Light.NoActionBar
- <style name="NoActionbarAppTheme" parent="Theme.AppCompat.Light.NoActionBar">
- <item name="colorPrimaryDark">@color/material_blue_700</item>
- <item name="colorPrimary">@color/material_blue_500</item>
- <item name="android:windowBackground">@color/white</item>
- <item name="android:textColorPrimary">@color/black</item>
- <item name="colorAccent">@color/material_green_A200</item>
- </style>
- android:fitsSystemWindows="true"
2.values-v19
- <style name="NoActionbarAppTheme_v19" parent="Theme.AppCompat.Light.NoActionBar">
- <item name="android:windowTranslucentNavigation">true</item>
- <item name="android:windowTranslucentStatus">true</item>
- <item name="colorPrimaryDark">@color/material_blue_700</item>
- <item name="colorPrimary">@color/material_blue_500</item>
- <item name="android:windowBackground">@color/white</item>
- <item name="android:textColorPrimary">@color/black</item>
- <item name="colorAccent">@color/material_green_A200</item>
- </style>
- android:fitsSystemWindows="true"
看效果与第一张类似,只是左边菜单划出的时候状态栏上面有暗色的阴影
3.values-v21
- <style name="NoActionbarAppTheme_v21" parent="Theme.AppCompat.Light.NoActionBar">
- <item name="colorPrimaryDark">@color/material_blue_700</item>
- <item name="colorPrimary">@color/material_blue_500</item>
- <item name="android:windowBackground">@color/bg</item>
- <item name="android:textColorPrimary">@color/black</item>
- <item name="colorAccent">@color/material_green_A200</item>
- <item name="colorControlHighlight">@color/material_blue_500</item>
- <item name="android:windowDrawsSystemBarBackgrounds">true</item>
- <item name="android:statusBarColor">@android:color/transparent</item>
- </style>
- android:fitsSystemWindows="true"
阅读全文
0 0
- SystemBarTint的使用(设置半透明状态栏)
- SystemBarTint的使用(设置半透明状态栏)
- SystemBarTint的使用(设置半透明状态栏)
- SystemBarTint的使用(设置半透明状态栏)
- Android 使用SystemBarTint设置状态栏颜色
- Android 使用SystemBarTint设置状态栏颜色
- 沉浸式状态栏的设定-com.readystatesoftware.systembartint:systembartint 的使用
- android透明状态栏与开源库SystemBarTint的使用
- SystemBarTint的使用
- Translucent System Bar 半透明状态栏的使用
- Android沉浸式状态栏SystemBarTint的使用方法
- Android沉浸式状态栏SystemBarTint的使用方法
- Android沉浸式状态栏SystemBarTint的使用方法
- Android沉浸式状态栏SystemBarTint的使用方法
- Android沉浸式通知栏的一个开源库SystemBarTint简单使用,android沉浸式状态栏
- Android头部状态栏SystemBarTint
- SystemBarTint沉浸式状态栏
- Android使用systembartint库实现沉浸式状态栏效果
- Delphi编译开关=====转帖收藏
- 没有校园网同样免费下知网文库论文
- 这就是我的测试人生
- 存储器的速度
- 让小白也能飞起(搭建SSR)--GOOGLECLOUD篇
- SystemBarTint的使用(设置半透明状态栏)
- Linux启动tomcat慢 解决方法
- MyEclipse中使用Maven前常见错误及解决办法
- Wifi知识点
- ftp工具无法连接到服务器上传失败
- Stanford机器学习---第五讲. 神经网络的学习 Neural Networks learning
- android图片加载- Glide基础使用
- postgrepsql安装入门
- HDFS副本机制