7 minutes

Android Lollipop Toolbar Example

By Nilanchala @nilan, On Sep 17, 2023 Android 2.28K Views


Android’s new operating system named Android Lollipop is highly focused on rich user experience and what they called it as material design. In this example, we will take a look at the new Actionbar replacement called Toolbar.

What is Toolbar?

The toolbar is a complete replacement to Android ActionBar. It provides greater control to customize its appearance, unlike old ActionBar. Using the Toolbar, the application developer can now, show multiple toolbars on the screen, spanning only part of the width, etc.

Android Toolbar Example
Screenshot showing simple toolbar in android tablet and phone.

It is introduced in Android Lollipop, API level 21 release, and hence it is available to use, out of the box for the application that is targeted to 21 and above. However, as always Google provides fully supported Toolbar features to lower android os devices via AppCompact support library. In AppCompat, Toolbar is implemented in the class.

A Toolbar can be used in two ways.

  1. Use a Toolbar as an replacement to ActionBar. In this you can still continued to use the ActionBar features such as menus, selections, etc.
  2. Use a standalone Toolbar, where ever you want to place in your application.

Using Toolbar as ActionBar

Following are simple steps you need to follow for implementing Toolbar as ActionBar replacement.

First of all, you need to disable ActionBar. To do this, you need to extend your application theme from Theme.AppCompat.NoActionBar or if you are already using Theme.AppCompact theme, then just add below lines of code snippet

<!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat">
        <item name="android:windowNoTitle">true</item>
        <item name="windowActionBar">false</item>

Secondly, add the App Compact V7 support support library. In this example, I am using Android Studio as the development IDE. You can add the V7 support library dependency to your application build.gradle file.

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile ""

Now you need to add Toolbar to your Activity layout. Find the code snippet below for simple Toolbar Layout.


Apply the theme to Activity. Here in this step you need to apply the theme which we have created in step-1 to your activity. This can be done, by using android:theme attribute in your application AndroidManifest.xml.

            android:theme="@style/AppTheme" >

Now you are almost ready. You just need to instantiate the Toolbar and add it to your activity by using setSupportActionBar(Toolbar) method.


public class MyActivity extends ActionBarActivity{

    protected void onCreate(Bundle savedInstanceState) {

        // Set a toolbar to replace the action bar.
        Toolbar toolbar = (Toolbar) findViewById(;
nilan avtar


I'm a blogger, educator and a full stack developer. Mainly focused on Java, Spring and Micro-service architecture. I love to learn, code, make and break things.