沉浸式效果是从安卓4.4开始实行的
首先需要三个values文件夹,默认文件夹values,values-v19,values-v21
那么我们需要做:
在values/styles.xml文件内加入不支持沉浸式任务栏的默认样式
<style name="TranslucentTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
在values-v19/styles.xml文件内加入
<style name="TranslucentTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
</style>
在values-v21/styles.xml文件内加入
<style name="TranslucentTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowTranslucentStatus">false</item>
<item name="android:windowTranslucentNavigation">true</item>
<!--Android 5.x开始需要把颜色设置透明,否则导航栏会呈现系统默认的浅灰色-->
<item name="android:statusBarColor">@android:color/transparent</item>
</style>
在APP theme中引入style即可实现APP沉浸式效果!