I think if you want to implement the effect you want, only setting Toolbar
overlay is not enough.
I implemented this before: Toolbar
can be collapsed or expanded when contents are scrolled up or down. Here below are my codes, take a look at it first:
<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:id="@+id/coordinator_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="me.danielpan.youtubelike.ProfileActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="192dp"
android:fitsSystemWindows="true"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="0dp"
app:collapsedTitleTextAppearance="@style/ThemeOverlay.AppCompat.Dark"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginBottom="32dp"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:expandedTitleTextAppearance="@style/ThemeOverlay.AppCompat.Light"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:paddingStart="0dp"
app:statusBarScrim="?attr/colorAccent">
<ImageView
android:id="@+id/profile_bg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
android:src="@mipmap/profile_bg"
app:layout_collapseMode="parallax" />
<android.support.v7.widget.Toolbar
android:id="@+id/anim_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:pressedTranslationZ="3dp"
app:fabSize="mini"
app:rippleColor="@color/swipe_refresh_color_scheme_blue_1"
app:borderWidth="3dp"
app:elevation="2dp"
android:src="@drawable/icon_plus"
android:layout_marginRight="20dp"
android:layout_marginBottom="20dp"
app:layout_anchor="@id/recycler_view"
app:layout_anchorGravity="bottom|right|end"
/>
</android.support.design.widget.CoordinatorLayout>
I set ThemeOverlay
to AppBarLayout
, CollapsingToolbarLayout
and Toolbar
. And this worked well: Toolbar
is transparent at first, when contents are scrolled up, Toolbar
becomes opaque and at last is in the color of my ImageView
by using Palette
.
Hope you'll be inspired by my codes, good luck~