2017-04-04 160 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)。