一、效果图
沉浸式.gif
二、代码实现
1.在styles.xml下新建一个style
<style name="TranslucentTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:windowTranslucentStatus">false</item>
<item name="android:windowTranslucentNavigation">true</item>
<!--Android 5.x开始需要把颜色设置透明,否则导航栏会呈现系统默认的浅灰色-->
<item name="android:statusBarColor">@android:color/transparent</item>
</style>
2.在AndroidManifest.xml的activity标签下加入上述style
<activity android:name=".MainActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan"
android:launchMode="singleTask"
android:theme="@style/TranslucentTheme"/>
3.在Activity的布局文件的根布局上加入android:fitsSystemWindows="true"
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:fitsSystemWindows="true"
android:layout_height="match_parent"
android:background="@drawable/bg_splash">
...
</LinearLayout>
另外需要注意的是:沉浸式状态栏只支持安卓4.4及以上的版本