標籤:art win sch -- 調用 param dev get 安卓
安卓4.4才有的沈浸式狀態列
在代碼設定:
if(VERSION.SDK_INT >= VERSION_CODES.KITKAT) { //透明狀態列 getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); //透明導覽列 getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);}
直接調用上面2行代碼可以透明,但是你會發現你的 view 跑到 actionbar 上面去了,很明顯
google 的意圖是使你的 view 可以佔據整個螢幕,然後 狀態列和導覽列 透明覆蓋在上面很明顯這樣不可行。
那有沒有辦法使你的 view 保持原來大小呢?
有,你需要在這個 activity 的 layout xml 檔案添加兩個屬性:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center_horizontal" android:fitsSystemWindows="true" android:clipToPadding="true" android:orientation="vertical" >
這樣狀態列的背景就是你的 activity 的主背景,倘若actionbar 在,將會很難看,
第二種方式,是是設定 theme 屬性
android:theme="@android:style/Theme.DeviceDefault.Light.NoActionBar.TranslucentDecor"android:theme="@android:style/Theme.Holo.Light.NoActionBar.TranslucentDecor"android:theme="@android:style/Theme.Holo.NoActionBar.TranslucentDecor"
複製代碼 如果你使用自定主題,只需在在 values-19 檔案添加以下屬性:
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar"> <!-- API 19 theme customizations can go here. --> <item name="android:windowTranslucentStatus">true</item> <item name="android:windowTranslucentNavigation">true</item></style>
複製代碼
剛剛說了這個使用有局限性,不過好在有一個開源的東西
https://github.com/jgilfelt/SystemBarTint
使用這個開源庫,必須開啟透明標題列
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar"> <!-- API 19 theme customizations can go here. --> <item name="android:windowTranslucentStatus">true</item> <item name="android:windowTranslucentNavigation">true</item></style>
使用這個主題或者在setContentView之前調用這個代碼
if(VERSION.SDK_INT >= VERSION_CODES.KITKAT) { //透明狀態列 getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); //透明導覽列 getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);}
Android 4.4 沈浸式透明狀態列與導覽列