Collapsing Action Bar, but only shows when RecyclerView fully displays the first element

I have a page that has an action folding effect similar to this: http://xmodulo.com/hide-show-toolbar-scrolling-android.html . But I want the action bar to appear only when the list already shows the first item, and not right away when I scroll down. How can I achieve this?

+5
source share
1 answer

The design library has an AppBarLayout component to accomplish this.

Enable Library:

 dependencies { compile 'com.android.support:design:22.2.0' } 

Wrap the Toolbar in the AppBarLayout with scrollFlags set to "scroll", wrap the entire layout in CoordinatorLayout and add the layout_behavior parameter of your scroll to @string/appbar_scrolling_view_behavior .

 <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/main_content" android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.design.widget.AppBarLayout android:id="@+id/appbar" android:layout_width="match_parent" android:layout_height="wrap_content"> <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"/> <!-- If you have tabs you can include them below the toolbar --> <android.support.design.widget.TabLayout android:id="@+id/tabs" android:layout_width="match_parent" android:layout_height="wrap_content" /> </android.support.design.widget.AppBarLayout> <!-- If you use a ViewPager, just add the layout_behavior to it instead of the RecyclerView --> <android.support.v7.widget.RecyclerView android:id="@+id/recyclerView" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior"/> </android.support.design.widget.CoordinatorLayout> 
+2
source

All Articles