Jude95 / SwipeBackHelper

make your activity can swipe to close
1.38k stars 268 forks source link

如何实现,状态栏跟着滑动返回,就是滑动时候整个屏幕都滑动 #60

Open tpnet opened 7 years ago

tpnet commented 7 years ago

在style加这个属性可以实现 <item name="android:windowTranslucentStatus">true</item> 但是这样子会导致toolbar向上滑动时候挡住状态栏。。这怎么解决呢

AndSync commented 7 years ago

@tpnet 我的解决方案 ,跟随着滑动其实就是要把状态栏背景颜色去掉 1、将状态栏设置成透明 2、设置fitsSystemWindows为true,这时状态栏下面会看到App主题背景的颜色,但状态栏是没有颜色的 3、 在主题里设置页面背景<item name="android:windowBackground">@drawable/app_bg</item> 4、这个背景用layer-list实现,因为toolbar颜色和页面内容颜色不一样所以才这样做,要让背景颜色分上下两个区域,使状态栏区域和toolbar颜色一致。

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- 顶部颜色 -->
    <item>
        <shape>
            <solid android:color="#FAFAFA"/>
        </shape>
    </item>
    <item
        android:top="25dp">
        <!--填充颜色-->
        <shape>
            <solid android:color="#f0f0f0"/>
        </shape>
    </item>
</layer-list>

这个适配还没有做好 如果toolbar颜色不是白色会好弄些,如果是白色更麻烦 另外沉浸式状态栏适配我用的是https://github.com/gyf-dev/ImmersionBar

tpnet commented 7 years ago

@AndSync 这样子就会导致,toolbar向上滑动时候,会在状态栏下面显示了,看图

图片

AndSync commented 7 years ago

@tpnet 需要设置 fitSystemWindow=true