Android沉浸式開發快速配置

快速配置沉浸式開發欄

Android 沉浸式全屏的實現方法

[導讀] Android 4 4 帶來了沉浸式全屏體驗, 在沉浸式全屏模式下, 狀態欄、 虛擬按鍵動態隱藏, 應用可 以使用完整的屏幕空間, 按照 Google 的說法, 給用戶一種 身臨其境 的體驗。先來看看QQ的效果

哈哈哈

  • 在res下創建values-v19文件夾,也可以創建values-v19
    這裏寫圖片描述

快速配置

  • 複製一份styles.xml到values-v19和v21中,19對應的api版本是4.4,如果創建v21,默認所有高於4.4的手機都會加載v19中的xml

  • styles配置

<resources>
    <!-- 創建一個主題樣式,指定不要actionBar標題欄 -->
    <style name="TransTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- 指定透明狀態爲true -->
        <item name="android:windowTranslucentStatus"> true</item>
    </style>
</resources>
  • 如果想更高級一點,把底部的選項欄都沉浸的的話可以這樣配置,下邊是不配置的選項欄
    這裏寫圖片描述
<resources>

    <!-- Base application theme. -->
    <style name="TransTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="android:windowTranslucentStatus"> true</item>
        <!-- 選項欄消失 -->
        <item name="android:windowTranslucentNavigation">true</item>
    </style>

</resources>
  • 在清單文件中引入新的主題
 <activity
            android:theme="@style/TransTheme"
            android:name=".MainActivity"
         >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
  • 在Activity對應的佈局中配置
<!--background 整體的背景色
android:fitsSystemWindows 適應系統屏幕-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"

    android:background="#00ff00"
    android:fitsSystemWindows="true"
    tools:context=".MainActivity">
  • 搞定啦—-跑一下子試試吧….
  • 本文轉載自dashi博客…
發佈了62 篇原創文章 · 獲贊 132 · 訪問量 55萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章