简体   繁体   English

CollapsingToolbarLayout中的内容被工具栏背景颜色遮盖

[英]Top of content in CollapsingToolbarLayout obscured by Toolbar background colour

I'm seeing an issue with my app when using the Android design support library in that the CollapsingToolbarLayout appears to have a theme-coloured background bar at the top, even when there is enough space (and therefore it should be 'transparent'). 我在使用Android设计支持库时看到我的应用程序存在问题,因为CollapsingToolbarLayout顶部似乎有一个主题色背景栏,即使有足够的空间(因此它应该是'透明')。

Any ideas what I'm doing wrong? 我有什么想法我做错了吗?

<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>

在此输入图像描述

I'm having very similar layout in my app and it's working well for me. 我的应用程序中的布局非常相似,而且对我来说效果很好。 Comparing mine layout to yours, my guess is you should remove background attribute from your Toolbar . 将矿山布局与您的布局进行比较,我猜您应该从工具栏中删除背景属性 Furthermore, I use one of the default themes for Toolbar (@style/ThemeOverlay.AppCompat.Dark). 此外, 我使用工具栏的默认主题之一 (@ style / ThemeOverlay.AppCompat.Dark)。 I see you're using your own theme, which might be causing problem as well. 我看到你正在使用自己的主题,这也可能导致问题。 (I set StatusBar color to transparent in Java code, if you're interested in that too). (我在Java代码中将StatusBar颜色设置为透明,如果您对此也感兴趣的话)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM