Android - How to fix the toolbar on top in AppBar

Viewed 2124

Im trying to fix the toolbar when scrolling through the content. Currently the toolbar disappears whe you scroll. I have tried this solution but I didn't manage to make it work. So far I have no solution on how to do so. Any help will be appreciated. Here is my XML Layout and a picture of the concerned layout.

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.design.widget.CoordinatorLayout
        android:id="@+id/coordinator"
        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:layout_width="match_parent"
        android:layout_height="match_parent">

    <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">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="220dp"
            app:layout_scrollFlags="scroll|enterAlwaysCollapsed"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light">

            <android.support.v4.view.ViewPager
                android:id="@+id/pager_most_read"
                xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="match_parent"
                android:layout_height="220dp"
                android:layout_alignParentTop="true"
                android:background="@android:color/transparent">
            </android.support.v4.view.ViewPager>

            <android.support.v7.widget.Toolbar
                android:layout_alignParentTop="true"
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="#0000ff"
                app:layout_collapseMode="pin">
            </android.support.v7.widget.Toolbar>

            <me.relex.circleindicator.CircleIndicator
                android:layout_alignParentBottom="true"
                android:id="@+id/indicator"
                android:layout_width="match_parent"
                android:layout_height="48dp" />

        </RelativeLayout>

        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/white"
            app:tabIndicatorColor="@color/text_selected"
            app:tabMode="scrollable"
            app:tabSelectedTextColor="@color/text_selected"
            app:tabTextColor="@color/gray"/>

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


    <ProgressBar
        android:id="@+id/progressBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        />

    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        />

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

enter image description here

1 Answers
Related