Android Collapsing Toolbar Tutorial

Google has developed new Material Design to improve better UI/UX in android application. The action bar was deprecated because it has many limitation in the android activity. So, it come out with toolbar which provide many extra features to replace old action bar. Android Collapsing Toolbar is a kind of scroll-able toolbar with image, it is very nice to show a image inside a toolbar to indicate a message in the activity. In this tutorial, I will give you some tips on doing collapsing toolbar in the android application so you will get use on it in the future.

Creating a New Project

1. Open Android Studio IDE in your computer.
2. Create a new project and Edit the Application name to “CollapsingToolbarExample”.
(Optional) You can edit the company domain or select the suitable location for current project tutorial. Then click next button to proceed.
3. Select Minimum SDK (API 15:Android 4.0.3 (IceCreamSandwich). I choose the API 15 because many android devices currently are support more than API 15. Click Next button.
4. Choose “Empty Activity” and Click Next button
5. Lastly, press finish button.

Add new Dependency

Go to build.gradle (module: app) and add the following dependency in your dependencies section.

Edit activity_main.xml layout

After that, go to your activity_main.xml and edit to the following source code. I add collapsingtoolbar layout and put imageview and toolbar inside to make collapsing effect on the toolbar. You can see the effect after you run it.

Edit class

In your add the toolbar and set the toolbar in your activity so you can see the toolbar appear in your android activity. You can following the source code below.

Run your project

Now, you can try and run it in your android device to see the collapse effect on the toolbar. You can try to scroll down and up in the activity.

(Android Collapsing Toolbar)

Source Code

(Visited 921 times, 1 visits today)

Yong Loon Ng

Ng Yong Loon, better known as Kristofer is a software engineer and computer scientist who doubles up as an entrepreneur.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *