The Android Toolbar has replaced the old action bar. It was introduced in API 21 (Android 5.0 Lollipop). In this tutorial we are going to implement it using the support library. Our goal is to implement a toolbar which is supported by older versions of Android as well. I am using Android Studio to demonstrate this Android toolbar tutorial.

Toolbar in Android

The Toolbar is a view group which can be placed anywhere in your activity. You can alter its size, color and position. You can make it behave like an action bar by adding a logo, labels, and navigation items.

Make the toolbar compatible with older versions

Whenever new API’s are introduced, their supporting libraries are also provided. For supporting material design, Android has provided the Appcompat v21 Library. We use it to implement a toolbar in an Android application.

Screenshot of an Android toolbar example

android toolbar

Create a new Android application and go to build.gradle (Module:app) which is present inside the gradle scripts. Make sure the following dependency is present. I have already written one tutorial on material design using Appcompat v21 Library. You can refer to it to get step by step details for getting started with material design.

Remove the old ActionBar

We need to remove the old actionbar from our theme. Open the res->values->styles.xml file and add the following lines of code. We have opted for the Theme.AppCompat.Light.NoActionBar theme which does not provide an action bar.

Go to your main Android xml file and add the following line of code to include a toolbar. It provides backwards compatibility. The toolbar is a normal view group and it has its own ID, color, width and height. You can add margins (left and right) by using the contentInsetEnd and contentInsetStart properties.

Implementing main activity

You need to extend your activity from ActionBarActivity. Refer to the below line of code to make sure that you are using the correct import statements.

Toolbar – A new ActionBar

Use this line of code below to make your toolbar behave like an action bar.

Below you can find the complete code of the main activity which implements the Android action toolbar. You can find code for the activity_main.xml file below.

How to add an actionbar or toolbar to the bottom of the screen.

The toolbar is a view group and it can be placed anywhere inside your activity. We can style it like other view groups. To make it appear on the bottom we need to add a new attribute to the toolbar element.

Remove the following lines of code from your textview. When you run your toolbar application, you can see the layout similar to the one which is showing below.


This is a basic example of adding a toolbar to an Android application. Please comment below with your queries and suggestion. Make sure to subscribe to our Facebook page for more updates. Thank you.