Loading...

How to Hide Toolbar/AppBarLayout When Content Scroll

In this tutorial, you will learn to hide and show Toolbar/AppBarLayout while scrolling the content/screen like Google play music, play store. If your application/game requires more space then you can hide toolbar on scroll. You can also do same thing for TabLayout also if you are using tabs along.

Here I have I have used Toolbar/AppBarLayout along with TabLayout and I am only hiding actionbar/toolbar while scrolling and tabs goes to at the top of screen below notification bar.

Related:
Android Toolbar Example: How to Use Toolbar as ActionBar
Android Navigation Drawer View: Material Design Support Library
Android Action Bar Tutorial and Example With Option Menu

Android Example: Hide and Show Toolbar/AppBarLayout Along with Scroll


Let’s start by creating new android project with the project name Hide and Show ActionBar.

Open your app build.gradle file and add the dependencies: compile 'com.android.support:design:23.1.0'

build.dradle

Open colors.xml and styles.xml file from res > values folder and add the following content.

res/values/colors.xml

res/values/styles.xml

XML Layout File

In XML layout file I have added Toolbar, AppBarLayout, TabLayout inside CoordinatorLayout and DrawerLayout with different attributes. Following is the complete content of XML layout file.

res/layout/hiding_toolbar_appbarlayout_when_content_scroll.xml

Java Activity File

Below is the complete java code of java activity file.

src/HideShowAppBarLayout.java

Android Example: Hide and Show Toolbar/AppBarLayout Along with Scroll

Now, run your How to Hide Toolbar/AppBarLayout When Content Scroll android application and scroll the content. You will see toolbar being collapsed and tabs will go to top of the screen like the above screenshot.
UI 3072885103139549657
Home item