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 MainActivity.java class

In your mainactivity.java 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 487 times, 1 visits today)
Advertisements

Kristofer Ng

A crazy android and web developer. Passion on developing android application and exploring new technology as a hobby.

You may also like...

Leave a Reply

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

GET YOUR EBOOK FOR FREE

Unlock free ebook "Beginning Programming ALL-IN-ONE Desk Reference for DUMMIES" now!

We will send a copy to your email