2

I would like to have Toolbar Collapsed when scrolled down but it does not work..

My activity.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:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context=.reviews.ReviewListActivity">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

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

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="?android:attr/actionBarSize"
        android:background="@color/bgLightGrey"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <TextView
            android:id="@+id/textNothingMessage"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginTop="48dp"
            android:gravity="top|center_horizontal"
            android:text="@string/msg_no_reviews"
            android:textColor="@color/secondaryText"
            android:textSize="24sp"
            android:visibility="invisible" />

        <android.support.v4.widget.SwipeRefreshLayout
            android:id="@+id/layoutSwipeRefresh"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <android.support.v7.widget.RecyclerView
                android:id="@+id/recyclerViewReviews"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />

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

    </FrameLayout>

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

My styles.xml

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>


<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
    <item name="android:windowBackground">@drawable/splash</item>
    <item name="android:windowTranslucentStatus">true</item>
</style>

<style name="AppTheme.StartTheme">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="android:windowTranslucentStatus">true</item>
</style>

<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.NoActionBar">
</style>

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

My AndroidManifest.xml

    <activity
        android:name=".reviews.ReviewListActivity"
        android:label="@string/title_activity_review_list"
        android:parentActivityName=".MainActivity"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme.NoActionBar">
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value=".MainActivity" />
    </activity>

It does kind of collapse... in a weird way. Toolbar moves up and goes under the system status bar but toolbar itself does not collapse. Sigh...

I have tried to put app:layout_behavior property on RecyclerView but didn't work.

What am I doing wrong??

I suspect Theme but I am using default themes created by Android Studio when I added a new activity.

Thanks in advance!

Eddie
  • 761
  • 3
  • 9
  • 22
  • Try adding `android:fitsSystemWindows="true"` to your `AppBarLayout`. – razzledazzle Mar 24 '16 at 03:17
  • @razzledazzle Hi, Thank you for the comment! I tried it but it only pushes the app bar under the status bar from the beginning (without scrolling) :-/ – Eddie Mar 24 '16 at 13:16

1 Answers1

2

It was a bug of Android Design Support Library 23.2.0.

I have updated it to 23.2.1 and it fixed the problem.

Add or replace line in app.gradle

compile 'com.android.support:support-v4:23.2.1'
compile 'com.android.support:design:23.2.1'

Reference: https://stackoverflow.com/a/36006211/4694036

Community
  • 1
  • 1
Eddie
  • 761
  • 3
  • 9
  • 22