Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Toolbar + Tab Layout + Drawer, Hide toolbar when scrolling and take TabLayout to the top

Tags:

I have activity which has drawer attached to it. Each menu of the drawer is a fragment, and under one of the menu I have a fragment with TabLayout, and each tab contains a RecyclerView. So now, when I scroll the RecyclerView, tab layout is getting hidden but ToolBar remains at the top. What I need is to ToolBar to get hidden(scrollFlags:scroll|enterAlways), and TabLayout should get shown at the top.

So current setup is:

Activity with attached DrawerLayout -> Fragment with TabLayout -> Tab Fragment 1 with RecyclerView -> Tab Fragment 2 with RecyclerView

like image 835
Vishal Pawale Avatar asked Nov 30 '15 13:11

Vishal Pawale


2 Answers

Less Code More Effective

Hello @Vishal i have found too much for you. because i am also searching this topic before some time.

I have found one brilliant library named MaterialViewPager this is fully customize with what you want to hide in scroll mode.

See the video on https://www.youtube.com/watch?v=r95Tt6AS18c

enter image description here

like image 189
Vishal Patel Avatar answered Oct 08 '22 05:10

Vishal Patel


Can you use the support design library? It has this behavior built in to do exactly what you have described. It uses CoordinatorLayout to accomplish this.

<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:animateLayoutChanges="true"     >     <android.support.design.widget.AppBarLayout         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">         <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/ThemeOverlay.AppCompat.Light" />         <android.support.design.widget.TabLayout             android:id="@+id/tabanim_tabs"             android:layout_width="match_parent"             android:layout_height="wrap_content" />     </android.support.design.widget.AppBarLayout>     <android.support.v4.view.ViewPager         android:id="@+id/tabanim_viewpager"         android:layout_width="match_parent"         android:layout_height="match_parent"         app:layout_behavior="@string/appbar_scrolling_view_behavior" />      <android.support.design.widget.FloatingActionButton         android:id="@+id/fab"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:src="@drawable/ic_alarm_add_white_48dp"         app:layout_anchor="@id/tabanim_viewpager"         app:layout_anchorGravity="bottom|right|end"         android:layout_margin="16dp"         />  </android.support.design.widget.CoordinatorLayout> 
like image 28
Tyler Pfaff Avatar answered Oct 08 '22 07:10

Tyler Pfaff