Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Back button not shown on collapsed state in CollapsingToolbarLayout

I have a CollapsingToolbarLayout It displays the back button on the expanded state, but not showing on the collapsed state.

I tried setNavigationIcon() on the Toolbar but it sets for the expanded state.

Here is the layout

<android.support.design.widget.CoordinatorLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="250dp"
    android:fitsSystemWindows="true">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/user_collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        app:contentScrim="@color/colorAccent"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

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

        <android.support.v7.widget.Toolbar
            android:id="@+id/user_toolbar"
            android:layout_width="match_parent"
            android:layout_height="?android:attr/actionBarSize"
            app:titleTextColor="@android:color/white"/>
    </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">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <include layout="@layout/pen_point_item_layout" />
        <include layout="@layout/pen_point_item_layout" />
    </LinearLayout>
</android.support.v4.widget.NestedScrollView>

Java:

toolbar = (Toolbar) findViewById(R.id.user_toolbar);
    toolbar.setNavigationIcon(R.drawable.ic_back);
    setSupportActionBar(toolbar);

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowTitleEnabled(true);
    collapsingToolbar = (CollapsingToolbarLayout) findViewById(R.id.user_collapsing_toolbar);
    collapsingToolbar.setTitle("Profile");
    collapsingToolbar.setCollapsedTitleTextColor(Color.WHITE);
    collapsingToolbar.setExpandedTitleColor(Color.WHITE);

enter image description here

enter image description here

What should I do?

like image 765
bradley101 Avatar asked Mar 22 '17 07:03

bradley101


Video Answer


1 Answers

Add layout_collapseMode to the toolbar.

app:layout_collapseMode="pin" 
like image 143
Alvin Varghese Avatar answered Sep 27 '22 15:09

Alvin Varghese