1

当使用Android设计支持库时,我看到了一个与我的应用有关的问题,即CollapsingToolbarLayout在顶部显示为主题颜色的背景条,即使存在足够的空间(因此它应该是“透明的”)。CollapsingToolbarLayout中的顶部内容被工具栏背景颜色遮挡

任何想法我做错了什么?

<android.support.design.widget.CoordinatorLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/main_content" 
android:layout_width="match_parent" android:layout_height="match_parent" 
android:fitsSystemWindows="true" tools:context=".MainActivity"> 

<android.support.design.widget.AppBarLayout android:id="@+id/appbar" 
    android:layout_width="match_parent" android:layout_height="wrap_content" 
    android:theme="@style/AppTheme.AppBarOverlay" 
    android:fitsSystemWindows="true"> 

    <android.support.design.widget.CollapsingToolbarLayout 
     android:id="@+id/collapsing_toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="400dp" 
     android:fitsSystemWindows="true" 
     app:contentScrim="?attr/colorPrimary" 
     app:expandedTitleMarginEnd="64dp" 
     app:expandedTitleMarginStart="48dp" 
     app:layout_scrollFlags="scroll|exitUntilCollapsed"> 


     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:scaleType="centerCrop" 
      android:fitsSystemWindows="true" 
      app:layout_collapseMode="parallax"> 
      <fragment 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" android:id="@+id/map" 
       android:name="com.google.android.gms.maps.SupportMapFragment" 
       /> 

      <FrameLayout 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:background="#66000000" 
       android:layout_alignParentTop="true" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentStart="true" /> 
     </RelativeLayout> 

     <android.support.v7.widget.Toolbar android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      app:popupTheme="@style/AppTheme.PopupOverlay" 
      app:layout_collapseMode="pin"> 

     </android.support.v7.widget.Toolbar> 

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

</android.support.design.widget.AppBarLayout> 

<android.support.v4.widget.NestedScrollView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior"> 
    <!-- content --> 
</android.support.v4.widget.NestedScrollView> 
</android.support.design.widget.CoordinatorLayout> 

enter image description here

回答

3

我在我的应用程序有非常相似的布局,它的工作很适合我。比较我的布局与你的,我的猜测是你应该从您的工具栏删除背景属性。此外,我使用工具栏(@ style/ThemeOverlay.AppCompat.Dark)的默认主题之一。我看到你正在使用自己的主题,这也可能导致问题。 (如果你对此感兴趣,我将StatusBar的颜色设置为透明的Java代码)。

+0

Confirmed.it works – 9patchcoder

相关问题