2017-04-04 158 views
2

我開發了一個CollapsingToolbarLayout屏幕。Android - 工具欄中的狀態欄中的協調器佈局中的片段

當我在活動中使用此佈局。一切正常。

但是當我在片段中使用它。工具欄在狀態欄下。

In activity

In Fragment

這是我的代碼。請幫幫我。謝謝。

<?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" 
    android:fitsSystemWindows="true" 
    > 
    <!--App Bar Layout--> 
    <android.support.design.widget.AppBarLayout 
     android:id="@+id/appbar_layout" 
     android:layout_width="match_parent" 
     android:layout_height="300dp" 
     android:fitsSystemWindows="true" 
     > 
    <android.support.design.widget.CollapsingToolbarLayout 
     android:id="@+id/collapsed_toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_scrollFlags="scroll|exitUntilCollapsed|snap" 
    app:contentScrim="?attr/colorPrimary" 
    > 
    <android.support.v4.view.ViewPager 
     android:id="@+id/view_pager" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:fitsSystemWindows="true" 
     app:layout_collapseMode="parallax"/> 
    <ImageView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:fitsSystemWindows="true" 
     app:layout_collapseMode="parallax" 
     android:src="@mipmap/ic_launcher" 
     /> 
    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     app:layout_collapseMode="pin" 
     app:popupTheme="@style/ThemeOverlay.AppCompat.Light" 
     > 
    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/lay_topbar" 
     > 
     <ImageView 
      android:id="@+id/img_logo" 
      android:layout_width="44dp" 
      android:layout_height="44dp" 
      android:background="#FF0000" 
      android:layout_centerVertical="true" 
      /> 
     <ImageButton 
      android:id="@+id/imb_home" 
      android:layout_width="44dp" 
      android:layout_height="44dp" 
      android:background="#00FF00" 
      android:layout_alignParentRight="true" 
      android:layout_centerVertical="true" 
      /> 
     <ImageButton 
      android:id="@+id/imb_cart" 
      android:layout_width="44dp" 
      android:layout_height="44dp" 
      android:background="#0000FF" 
      android:layout_toLeftOf="@id/imb_home" 
      android:layout_centerVertical="true" 
      /> 
    </RelativeLayout> 
    </android.support.v7.widget.Toolbar> 

</android.support.design.widget.CollapsingToolbarLayout> 
+1

將此android:fitsSystemWindows =「true」更改爲android:fitsSystemWindows =「false」。 –

+1

你好@AishwaryaTiwari: 其實,我想在狀態欄顯示內容時,我向上滾動。 –

+0

檢查這個http://stackoverflow.com/questions/29738510/toolbar-overlapping-below-status-bar – rafsanahmad007

回答

1

請更改

android:fitsSystemWindows="true" 

android:fitsSystemWindows="false" 

。希望這會幫助你。

+0

謝謝你的幫助。但它不工作:( –

0

嘗試在CollapsingToolbarLayout中添加以下語句。

機器人:fitsSystemWindows = 「真」

0

我有同樣的問題。 將android:fitsSystemWindows =「true」放入Activity的佈局(包含片段的Activity)的根目錄中,而不是在片段佈局的根目錄(在您的情況下是CoordinatorLayout)。