How to show collapsed elements in CoordinatorLayout programmatically?

tse picture tse · Jun 10, 2015 · Viewed 7.2k times · Source

I have CoordinatorLayout as described in blog: http://android-developers.blogspot.ru/2015/05/android-design-support-library.html

<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.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

  <android.support.design.widget.AppBarLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content">
     <android.support.v7.widget.Toolbar
              ...
              app:layout_scrollFlags="scroll|enterAlways">

     <TextView
              ...
              app:layout_scrollFlags="scroll|enterAlways">
   </android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>

Inside AppBarLayout I have Toolbar and TextView with additional status info. AppBarLayout can be collapsed (after scrolling). Sometimes I need to show AppBarLayout in order to show changed status.

How to do it programmatically?

Answer

Mario Velasco picture Mario Velasco · Dec 4, 2015

As mentioned in other comment:

Using support libs v23 you can call appBarLayout.setExpanded(true/false)