Tech tip of this week

Android: How to use Toolbar

Toolbar is a replacement to Android ActionBar. It has many features to customize its appearance unlike old ActionBar.

Toolbar is introduced in Android Lollipop, API level 21.
Google provides fully supported Toolbar features to lower android os devices via AppCompact support library.

In AppCompat, Toolbar is implemented in the class.

Create Toolbar:

1. First of all, we need to disable ActionBar
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

2. We have to add AppCompact library in build.gradle file
    compile ""

3. Apply the theme to Activity.
   <activity android:name="com.example.sample.MyActivity"

      android:theme="@style/AppTheme" >

4. Add Toolbar in activity layout


            android:layout_height="wrap_content" >                                                </>

5. You just need to instantiate the Toolbar and add it to your activity by using         setSupportActionBar(Toolbar) method.

    public class MyActivity extends ActioBarActivity {
        protected void onCreate(Bundle savedInstanceState)

           Toolbar toolbar = (Toolbar) findViewById(;


No comments:

Post a Comment