CollapsingToolbarLayout change and leave transparent

2

I am not able to change the color of CollapsingToolbarLayout When I roll up it gets the image I placed and does not change the color.

Before:

Then:

I wanted to take the image and leave the toolbar transparent.

    
asked by anonymous 01.12.2016 / 14:45

1 answer

1

You can add contentScrim CollapsingToolbarLayout and leave the toolbar background transparent, but with opacity, or if you prefer with a solid color. Since you did not put any code, it would look something like this:

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

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/image"
            android:fitsSystemWindows="true"
            app:layout_collapseMode="parallax"
            android:scaleType="centerCrop"/>

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            app:layout_collapseMode="pin"/>

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

A GIF is worth more than a thousand images

Asshownintheimageabove,thecolorofToolbarissolid.Tobetransparent,simplychangethevaluefromcontentScreemtoacolorthathasopacity.Forexampleapp:contentScrim="#77000000" . See the image below:

    
10.02.2017 / 14:04