1.设置全屏

<!-- 全屏-启动页最下面的各种状态栏也去掉,清单中启动Activity援用-->    <style name="FullScreenTheme" parent="Theme.AppCompat.Light.NoActionBar">        <!-- Customize your theme here. -->        <item name="android:windowNoTitle">true</item>        <item name="android:windowFullscreen">true</item>        <item name="android:windowIsTranslucent">true</item>    </style><!--没有title,在application的theme中援用-->    <style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">        <!--<item name="android:windowNoTitle">true</item>-->    </style>
 <application        android:allowBackup="true"        android:icon="@mipmap/ic_launcher"        android:label="@string/app_name"        android:roundIcon="@mipmap/ic_launcher_round"         android:supportsRtl="true"        android:theme="@style/AppTheme"> //在这援用        <activity android:name=".StartActivity"            android:configChanges="orientation|keyboardHidden|screenSize"            android:theme="@style/FullScreenTheme" //在这援用            >   

2启动页倒计时跳转

https://gitee.com/hjmayun/codes/wofkb9z1y72e845xid0jg24

3 沉迷式状态栏

沉迷式状态栏最好不要从代码中设置,在代码中会有个变色的过程,不是想要的成果

1 新建两个文件夹values的 -v19,-v21的:

v19的styles.xml

<?xml version="1.0" encoding="utf-8"?><resources>    <!--values-19. v19开始有android:windowTranslucentStatus这个属性,这个属性为将状态-->    <style name="TranslucentStatusTheme" parent="AppTheme">        <item name="android:windowTranslucentStatus">true</item>    </style></resources>

v21的styles.xml

<?xml version="1.0" encoding="utf-8"?><resources>    <style name="TranslucentStatusTheme" parent="AppTheme">         <item name="android:windowTranslucentStatus">false</item>        <!--下部的导航栏也设置成沉迷-->         <item name="android:windowTranslucentNavigation">true</item>         <item name="android:windowDrawsSystemBarBackgrounds">true</item>        <!-- Android 5.x开始须要把色彩设置通明,否则导航栏会出现零碎默认的浅灰色-->        <item name="android:statusBarColor">@android:color/transparent</item>    </style></resources>

能够看到,零碎应用的都是TranslucentStatusTheme这个主题,只不过在不同api下他的属性有差异。

在values的style.xml下

我的AppTheme是NoActionBar的

<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">        <!--title(actionbar)的色彩-->        <item name="colorPrimary">@color/black</item>        <!--状态栏色彩-->        <item name="colorPrimaryDark">@color/transparent</item>        <!--浮动的button、光标色彩-->        <item name="colorAccent">@color/bluelogin</item>    </style>

写一个TranslucentStatusTheme,空实现就能够:

<style name="TranslucentStatusTheme" parent="AppTheme">    </style>

2 在清单manifest.xml中,application援用这个主题即可

 <application        .....        android:theme="@style/TranslucentStatusTheme">

3 留神

在layout的xml下的根布局须要增加属性:android:fitsSystemWindows="true"

<?xml version="1.0" encoding="utf-8"?><androidx.constraintlayout.widget.ConstraintLayout     ....    android:fitsSystemWindows="true"   ....    >

增加这个属性之后,底下的导航栏才会有一个绝对的沉迷式的展现。

以上的沉迷成果最好别设置title,否则会有各种坑,计算起来很麻烦

4 参考

Android 沉迷式状态栏适配计划

android沉迷式状态栏、fitsSystemWindows、标题栏折叠