<item name="android:statusBarColor">@android:color/transparent</item>
布局文件
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:orientation="vertical" android:fitsSystemWindows="true" android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.design.widget.AppBarLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:elevation="4dp" app:layout_scrollFlags="scroll|enterAlways"/> </android.support.design.widget.AppBarLayout> <android.support.v7.widget.RecyclerView android:id="@+id/content_list" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior" /> </android.support.design.widget.CoordinatorLayout>
toolbar 会滑动到 statusbar 的区域,最后的状态类似于 只要我添加上
android:fitsSystemWindows="true"
就会出现这个问题。
![]() | 1 PPTing 2016-08-13 23:02:33 +08:00 via Android 给 toolbar 加个 paddingTop 就好了 具体的值你可以计算出 statubar 的高度 我记得是 24dp (api23)和 25dp |
![]() | 2 ilumer OP @PPTing 没有使用 Immersive Full-Screen Mode ,是滑动到最后的时候会出现类似的这个状态,没有滑动还是很正常的。也是这样解决吗? |
3 woyaokshini 2016-08-13 23:58:39 +08:00 @PPTing 同意观点,感觉可以再改进一下,也许通过 activity.getResources().getIdentifier("status_bar_height", "dimen", "android")获取会不会更好一点,考虑到机型有差异性。 |
![]() | 4 ilumer OP @woyaokshini 动态家 padding 不是在使用了全屏模式的时候才需要的吗?我这里是使用了 fitsystemwinddows 后 toolbar 和 statusbar 感觉成了一个控件 上滑隐藏的时候,全部上滑了。和我预计的 statusbar 不移动有区别(希望没有说错)类似于这个 http://stackoverflow.com/questions/32074805/toolbar-scrolling-under-status-bar |
![]() | 5 blackbbc nbsp; 2016-08-14 00:41:24 +08:00 在最外面并列加一个空的 view ,宽高设置 match_parent 并且置 fitsystemwindow 然后 CoordinatorLayout 取消 fitsystemwindow ,然后在代码里面设置 margin 等于空的 view 的 margin 反正我是这么干的 |
![]() | 6 miao1007 2016-08-14 15:46:08 +08:00 以前写过这个,什么 XML 都不用写,一行 Java 代码搞定 http://www.jianshu.com/p/4f71b98dd6f9 |
7 kitalphaj 2016-08-16 10:34:08 +08:00 直接在 AppBarLayout 下面加上 android:fitsSystemWindows="true"就好了,这个是标准的解决方法。 |