Skip to content Skip to sidebar Skip to footer

Drawerlayout + Collapsingtoolbar + Fragments; Toolbar Won't Collapse Or Show Image

As the title suggests, I have an activity that has a FrameLayout that houses my Fragments [I am NOT using a Tabs, just Transactions]. I also have a NavigationDrawer and Toolbar.

Solution 1:

It turned out that the layout I was using for the Toolbar did not have the correct height value.

overlay_toolbar.xml

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    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="wrap_content"
    android:background="@color/get_blue"
    android:elevation="5dp"
    android:minHeight="?attr/actionBarSize"
    app:theme="@style/actionbar_getblue">

</android.support.v7.widget.Toolbar>

Adjustment to overlay_toolbar include call in Activity XML

<include
    android:id="@+id/toolbar"
    layout="@layout/overlay_toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    app:layout_collapseMode="pin"/>

After that single adjustment to the height the CollapsingToolbarLayout began working perfectly.

Solution 2:

app:layout_behavior should be applied to RecyclerView or any other View capable of nested scrolling such as NestedScrollView.

See this tutorial from codepath: https://guides.codepath.com/android/Handling-Scrolls-with-CoordinatorLayout

You can use app:layout_behavior="@string/appbar_scrolling_view_behavior" on RecyclerView you have in fragment.

Post a Comment for "Drawerlayout + Collapsingtoolbar + Fragments; Toolbar Won't Collapse Or Show Image"