0

I am creating an activity with collapsing toolbar layout.
My toolbar has different color and with a parralax image.
What i want is to get I have different color of toolbar and when collpased,
the toolbar color will be change to another color.

Here's my XML.

<?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:fab="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:background="@color/colorWhite"
android:fitsSystemWindows="true"
tools:context="com.toweelo.activity.ViewReviews">

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbarLayout"
    android:layout_width="match_parent"
    android:layout_height="310dp"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    app:elevation="0dp">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/colorPrimaryDark"
        app:contentScrim="@color/colorPrimaryDark"
        app:expandedTitleMarginEnd="64dp"
        app:expandedTitleMarginStart="48dp"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <ImageView
            android:id="@+id/img_content"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/toweelo_2"
            android:fitsSystemWindows="false"
            android:scaleType="centerCrop"
            app:layout_collapseMode="parallax"/>


        <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="64dp"
                android:background="@color/colorWhite"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light">

                <TextView
                    android:id="@+id/toolbarTitle"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:ellipsize="end"
                    android:gravity="center_vertical"
                    android:maxLines="2"
                    android:text=""
                    android:textColor="@color/colorBlack"
                    android:textSize="18dp"/>
            </android.support.v7.widget.Toolbar>

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

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

<include layout="@layout/content_view_reviews"/>

ATM, i only getting this result.
The white is my toolbar. And it should be white at start,
and then after collapsing it would be chnage to other color. enter image description here

I want the image to be under the toolbar.

Here is the sample of what am i doing..
In the first image, its not yet collpased.
And when the user scroll, the result will be the image 2 enter image description here

Charles Galvez
  • 1,100
  • 5
  • 19
  • 41

1 Answers1

0

This is what you need, check the implementation and replace your things in it:

<?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"
    android:id="@+id/fab_coordinator_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#EEEEEE"
    android:fitsSystemWindows="true">

    <android.support.v4.widget.NestedScrollView
        android:id="@+id/scroll"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clipToPadding="false"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <include layout="@layout/activityusrlayout" />

    </android.support.v4.widget.NestedScrollView>

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            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">

                <ImageView
                    android:id="@+id/image"
                    android:layout_width="match_parent"
                    android:layout_height="250dp"
                    android:layout_alignParentStart="true"
                    android:background="@drawable/header"
                    android:contentDescription="@string/imghd"
                    android:fitsSystemWindows="true"
                    android:scaleType="centerCrop"
                    app:layout_collapseMode="parallax" />


            </RelativeLayout>

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

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

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

    <de.hdodenhof.circleimageview.CircleImageView
        android:id="@+id/profile_image"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:layout_marginBottom="30dp"
        android:clickable="true"
        android:src="@drawable/ic_acc"
        app:layout_anchor="@id/app_bar_layout"
        app:layout_anchorGravity="bottom|center" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="16dp"
        android:src="@drawable/ic_remove_acc"
        app:backgroundTint="#DD2C00"
        app:fabSize="normal"
        app:layout_anchor="@id/fab_coordinator_layout"
        app:layout_anchorGravity="right|bottom" />

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

Here is the important code inside CollapsingToolbarLayout:

 app:contentScrim="?attr/colorPrimary"
ʍѳђઽ૯ท
  • 16,646
  • 7
  • 53
  • 108