不怕跌倒,所以飞翔

沉浸式状态栏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的分析

项目地址

更多相关文章

  1. Spring系列学习之Spring Android
  2. 基于Android客户端的人人网开放平台开发系列教程 (有源码哦)
  3. android:onTouch()和onTouchEvent()的区别?看完这篇文章就知道了
  4. 关于android中几个Info系列类的总结
  5. Android应用开发提高系列(4)――Android动态加载(上)――加载未安装A

随机推荐

  1. Android(安卓)解决监听home键的几种方法
  2. Android(安卓)采用工厂类创建对话框
  3. android 利用path 实现手写板的手写效果
  4. andrid layout_weight 计算 分析
  5. android 修改标题样式以及内容
  6. Android(安卓)调用系统照相机拍照和录像
  7. Android(安卓)使用 kotlin 协程
  8. Android(安卓)API之Telephony.Sms
  9. 通过Criteria获取LocationProvider
  10. Android编程5:数据库Sql编程