该使用 fitsSystemWindows 了!
Read more: http://blog.chengyunfeng.com/?p=905#ixzz5w5dFGaMm
我们为什么要用fitsSystemWindows?
深入理解 fitsSystemWindows
https://juejin.im/entry/59469d3f61ff4b006cf363ca
https://github.com/unixzii/android-source-codes/tree/master/UnderstandingFitsSystemWindows
Android中fitsSystemWindows属性的用法总结
https://blog.csdn.net/baidu_32472003/article/details/79925766
Android透明状态栏与状态栏文字颜色更改
https://www.jianshu.com/p/7392237bc1de
使用流程:使用在状态栏配置成透明时,页面的内容区域需要展示在状态栏下并且需要控制好内容区域的边界,保持和状态栏高度的边界。
下面的方法无法实现修改状态栏文字颜色
1,只是配置状态栏背景色,不是全屏
DrawerLayout加入android:fitsSystemWindows="true"
NavigationView也需要加入android:fitsSystemWindows="true",这样侧边栏区域才会显示在状态栏下面,insetRect值由DrawerLayout传递的
DrawerLayout只有配置了fitsSystemWindows才会全屏。
如果DrawerLayout的子View没有配置fitsSystemWindows,那么会对其子View设置margin,如果子View配置了fitsSystemWindows,则会将insetRect传递给子View,由子View处理。
此处,因为NavigationView配置了fitsSystemWindows,所以该子View的内容区域是占据了状态栏高度的。
因为CoordinatorLayout没有配置fitsSystemWindows,所以对该子View设置了topmargin。
附:
内容区域,因为是CoordinatorLayout布局,