Android的沉浸式

一、效果圖

沉浸式.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及以上的版本

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容