MaterialDesign系列文章(六)沉浸式状态栏的使用
不怕跌倒,所以飞翔
沉浸式状态栏Translucent System Bar
实现沉浸式状态栏有两种办法:
1.通过style进行设置(类似于中华万年历,这种适合顶部是直接显示图片这种)
首先就是要分别设置三个style,这里主要是通过设置android:windowTranslucentStatus,android:windowTranslucentNavigation,android:statusBarColor等三个属性进行设置
-
values/style.xml(这个是正常的主题)
``` ```
-
values-v19/style.xml(这个是19版本的时候使用的主题)
-
values-v21/style.xml(这个是21版本的时候使用的主题)
设置完成之后要在清单文件的Activity中设置主题,然后要在每个页面的跟标签添加一个属性android:fitsSystemWindows="true"至此就可以实现第一种沉浸式的状态栏了,但是这里注意一个问题就是如果使用toolBar的话那些属性在其他两个清单文件也要设置
2.Tab栏和系统导航栏分开设置(类似于QQ音乐,这种适合顶部是纯色的)
这种相对于上面那种方式的话简单一点(但是这种实现的话,不变成页面多次绘制的问题)
- values-v21/style(这个是21版本都得时候使用的主题)
这个也需要对 android:fitsSystemWindows="true" 这个属性进行设置,然后在设置toolBar的颜色或者是自己实现布局的颜色
3.一些简单的设置
每个布局都需要设置 android:fitsSystemWindows="true" 确实很麻烦,所以使用代码设置的话是不是会很好
ViewGroup contentFrameLayout = (ViewGroup) findViewById(Window.ID_ANDROID_CONTENT); View parentView = contentFrameLayout.getChildAt(0); if (parentView != null && Build.VERSION.SDK_INT >= 14) { parentView.setFitsSystemWindows(true); }
通过上面的代码就可以不必在每一个页面都设置 android:fitsSystemWindows="true" 这个属性了
这一系列文章的地址,希望对大家有帮助
MaterialDesign系列文章(一)转场动画
MaterialDesign系列文章(二)Theme主题设置
MaterialDesign系列文章(三)Palette库来获取图片的主要色彩
MaterialDesign系列文章(四)RecealAnimation动画的使用
MaterialDesign系列文章(五)ToolBar的使用
MaterialDesign系列文章(六)沉浸式状态栏的使用
MaterialDesign系列文章(七)TabLayout的使用
MaterialDesign系列文章(八)CollapsingToolbarLayout的使用
MaterialDesign系列文章(九)AppBarLayout的使用
MaterialDesign系列文章(十)NavigationView和DrawerLayout的使用
MaterialDesign系列文章(十一)NestedScrollView的使用
MaterialDesign系列文章(十二)TextInputLayout的使用
MaterialDesign系列文章(十三)FloatingActionButton的使用
MaterialDesign系列文章(十四)SnackBar的使用
MaterialDesign系列文章(十五)BottomSheet的使用
MaterialDesign系列文章(十六)BottomNavigationView的使用
MaterialDesign系列文章(十七)Behavior的相关问题
CoordinatorLayout的分析
项目地址
更多相关文章
- Android(安卓)Http请求的代码
- 设置Activity全屏
- Qt on Android(安卓)Episode 4(翻译)
- Android(安卓)显示不满屏的问题解决
- Android(安卓)支持多屏幕机制
- 一个不错的启动菜单显示屏动画效果
- 箭头函数的基础使用
- NPM 和webpack 的基础使用
- Python list sort方法的具体使用