1、先在style中把 statusBarColor 設置為透明 如下
<item name="android:statusBarColor">@android:color/transparent</item>
2、使用material design的頁面中,使全屏顯示
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
3、針對本人自己的情況,我是在toolbar的上面放了一張圖片,默認圖片會顯示在狀態欄下面,此時在imageview外套一個framelayout設置
android:fitsSystemWindows為true,圖片就會全屏顯示,壓在狀態欄下面。
/此時需要給toolbar設置一個狀態欄高度的 margin值,否則,會使toolbar跟狀態欄重疊,toolbar中的文字顯示不全。因為5.0新特性,當toolbar向上移動時,會默認顯示在狀態欄的下面
我們做了全屏顯示的設置后,toolbar就會跟狀態欄重疊。此時可以設置toolbar的margintop為 狀態欄高度(6.0為24dp 以下為25dp)
<?xml version="1.0" encoding="utf-8"?> <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.chuangyuan.qdocument.activity.AboutActivity"> <android.support.design.widget.AppBarLayout android:id="@+id/appbar" android:layout_width="match_parent" android:layout_height="300dp" android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> <android.support.design.widget.CollapsingToolbarLayout android:id="@+id/collapsing" android:layout_width="match_parent" android:layout_height="match_parent" app:contentScrim="?attr/colorPrimary" app:layout_scrollFlags="scroll|exitUntilCollapsed"> <FrameLayout //外面套上framelayout並設置 android:layout_width="match_parent" android:layout_height="wrap_content" android:fitsSystemWindows="true"> <ImageView android:layout_width="match_parent" android:layout_height="230dp" android:src="@drawable/head" android:scaleType="centerCrop" app:layout_collapseMode="parallax" /> </FrameLayout> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" app:layout_collapseMode="pin" android:background="@android:color/transparent" android:layout_marginTop="24dp" //此時需要給toolbar設置一個狀態欄高度的 margin值,否則,會使toolbar中的文字顯示不全。 /> </android.support.design.widget.CollapsingToolbarLayout> </android.support.design.widget.AppBarLayout> <android.support.v4.widget.NestedScrollView android:id="@+id/nested" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="a。。。代表很多字" /> </LinearLayout> </android.support.v4.widget.NestedScrollView> </android.support.design.widget.CoordinatorLayout>