I updated the Android support library from 23.1.1 to 23.2.1 , and the AppBarLayout setExpanded method no longer works as before.
I have a CollapsingToolbarLayout that takes up the whole screen, and below it there is a NestedScrollView containing other views. Scrolling up and down completely collapses / expands the layout of the toolbar, thereby displaying or hiding the scroll view with content.
Manual checks work fine, but I also have a button that launches the AppBarLayout setExpanded method with true/false options to automatically minimize / expand the toolbar. With version 23.1.1 this method also works correctly, but with 23.2.1 only the first minimization of the toolbar will show the contents below the scroll, all subsequent collapses will not. The setExpanded(true) launch method, when the toolbar is minimized, will show the contents of my scroll view, and the expanding animation will work the way it should work.
The problem can be reproduced on devices / emulators with API 22 and below.
Any ideas how I can fix this behavior in library 23.2.1 ?
A basic example demonstrating the behavior above:
MainActivity.java
package com.test.displaym; import android.support.design.widget.AppBarLayout; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void btnClick(View v) { View iv = findViewById(R.id.image_view); AppBarLayout bar = (AppBarLayout) findViewById(R.id.app_bar); if (iv.getTop() == 0) bar.setExpanded(false); else bar.setExpanded(true); } }
activity_main.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" xmlns:app="http://schemas.android.com/apk/res-auto" tools:context="com.test.displaym.MainActivity"> <android.support.design.widget.CoordinatorLayout android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" > <android.support.design.widget.AppBarLayout android:id="@+id/app_bar" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" > <android.support.design.widget.CollapsingToolbarLayout android:id="@+id/toolbar_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" app:contentScrim="@color/colorPrimary" app:layout_scrollFlags="scroll|exitUntilCollapsed"> <ImageView android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/image_view" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:fitsSystemWindows="true" android:scaleType="centerCrop" app:layout_collapseMode="parallax"/> </android.support.design.widget.CollapsingToolbarLayout> </android.support.design.widget.AppBarLayout> <android.support.v4.widget.NestedScrollView 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:id="@+id/page_scroll" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior"> <TextView android:id="@+id/page" android:layout_width="match_parent" android:layout_height="wrap_content" android:text = "Some text\n12345\n" android:orientation="vertical"> </TextView> </android.support.v4.widget.NestedScrollView> </android.support.design.widget.CoordinatorLayout> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Scroll" android:id="@+id/button" android:onClick="btnClick" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true"/> </RelativeLayout>
build.gradle
apply plugin: 'com.android.application' android { compileSdkVersion 23 buildToolsVersion "23.0.2" defaultConfig { applicationId "com.test.displaym" minSdkVersion 15 targetSdkVersion 23 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.2.1' compile 'com.android.support:design:23.2.1' compile 'com.android.support:support-v4:23.2.1' }
The remaining project files are the same as in the base Android Studio project with empty activity.
- Screenshot of the correct behavior - the text should be constantly displayed during the expansion / expansion of the animation launched using the
SCROLL button. It should not be displayed only when the toolbar (blue area) completely covers the screen.

- Screenshot with impaired behavior - the text is not displayed when the toolbar animation is
SCROLL by the SCROLL button.

The red arrow in the above screenshots shows the area of ββthe screen that should be observed.