一、效果圖

沉浸式.gif
二、代碼實(shí)現(xiàn)
1.在styles.xml下新建一個(gè)style
<style name="TranslucentTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:windowTranslucentStatus">false</item>
<item name="android:windowTranslucentNavigation">true</item>
<!--Android 5.x開始需要把顏色設(shè)置透明,否則導(dǎo)航欄會(huì)呈現(xiàn)系統(tǒng)默認(rèn)的淺灰色-->
<item name="android:statusBarColor">@android:color/transparent</item>
</style>
2.在AndroidManifest.xml的activity標(biāo)簽下加入上述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>
另外需要注意的是:沉浸式狀態(tài)欄只支持安卓4.4及以上的版本