標籤:透明通知欄
從4.4開始,Google為Android增加了透明狀態列和導覽列的功能,只需要加入少量代碼就可以實現。
在Activity的布局檔案父View中添加屬性:android:fitsSystemWindows="true"和android:clipToPadding="true"即可。
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:custom="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" android:clipToPadding="true" android:background="#ffe5ff3e"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <TextView android:layout_width="match_parent" android:layout_height="match_parent" android:padding="16dp" android:textSize="18sp" android:text="@string/mytext" /> </LinearLayout></ScrollView>
如果不想要ActionBar,可以在AndroidManifest.xml或者Activity中去除,就得到效果。但是,透明通知欄只支援4.4以上的系統,在4.4以下還是會顯示預設的通知欄。
如果希望修改通知欄顏色,可以參考Github大牛的Demo:
https://github.com/jgilfelt/SystemBarTint
其中的library只有一個SystemBarTintManager類,可以拷貝到自己的工程中使用,這樣就不用依賴那個library了。
仿IOS透明通知欄(僅支援4.4以上版本)