Introduction

In this lecture we will describe about how can create Toolbar in Android Material design.And also describe what is Toolbar. why we can use it.After reading this lecture you will understand Toolbar. And i hope you will create App bar or Toolbar of your application.

Prerequisite

If you not understand this lecture. Toolbar in android  Material design.You should also read my previous lectures  How to Create Project – Material design And Toggle button in android studio.This is a complete series for beginners. After reading these lecture you will also able Understand Material design and also create app bar of your application.

What is Toolbar

In any application Toolbar are appears at the top of the screen.These are the boxes at the top and control the different function of the application.Each box have there own functionality .Toolbar are also provide a quick access to use the different functionality of application.Toolbar are also called action bar used for layout while there is a part of activity.It always consists of Navigation button Logo image and title and subtitle.The Action Bar was both less customizable and hard to style.New components are available in API 5.0 and above

Toolbar in Android Material design

Implementation Section

  • First part we describe how can add Toolbar in app
  • Second part we describe how can Customize the Toolbar in app
  • Third part we describe how can add action in Toolbar bar

These are some step that  are use to make ToolBar

  1. Use the Theme.AppCompact.Light.NoActionBarActivity to prevent system for showing action bar.
  2. Define app_bar.XML for containing a Toolbar.
  3. Use <include> in your layout.xml to add the Toolbar.
  4. Instantiate the toolbar using FindViewById inside the activity
  5. Call SetSupportActionBar() and pass your Toolbar object.
  6. Customize the App:Them And Popup them.

After that you will open Style.XML file and write the following code

And Write the following code Style. XML (V21)

Now we create a new Layout.

Step 1=<- create a new Layout name app_bar.XMl->Right click> the ->layout folder-> select ->New option-> and click ->layout resource folder->

Step3=Step2->WriteName->Ok.

Alt Tag android material design image for toolbar

And Write the following code app_bar layout. XML file

After that you will open color.XML file and write the following code

After that you will open activity_main.XML file and write the following code

After that you will open MainAvtivity.java class file and write the following code

Run the Application

Alt tag Toolbar in android material design


  •     Second part we describe how can Customize the Toolbar in app

In this part we learn about how can customize the the Toolbar .So how can change the color So this is a work that will done this section.please read this lecture carefully all the detail is provides step by step.For more detail about How can customize the Toolbar in android material design please click on customize the Toolbar in android material design

After that you will open Style.XML file and write the following code

After that you will open color.XML file and write the following code

And Write the following code app_bar layout. XML file

Run the Application

Alt Tag toolbar abdroid materiald esign customize


  • Third part we describe how can add action in Toolbar bar

In this part we learn about how can can add action in Toolbar bar.In this part we add a image in app bar or toolbar and when user click on a image button or navigation then can be move in next page or open a new activity.In second Activity inside the app bar we also add a button. when user click on this button also move in your Main Activity. So this is a work that will done this section.please read this lecture carefully all the detail is provides step by step.For more detail about How can customize the Toolbar in android material design please click on customize the Toolbar in android material design.

Step 1=Image add<-copy image->and<-paste image>into <-drawable folder-> that are used in app bar.

And Write the following code menu_main . XML file

We need to create a new  how can create following the below steps.

Step2: <-ADDActivity name SubActivity ->Click on <-java folder-> and expand this folder and right click on <-package name-> select <-new option-> then  you select <-activity option-> they are many categories then you finally  select <-blank activity-> show in below pic.

Alt Tag material design

 Step3=Step2->WriteName->Ok

After that you will open activity_sub.XML file and write the following code

After that you will open SubAvtivity.java class file and write the following code

Note

When you run the application its gives errors. So you will open a manifests file add the following code inside Activity.

After that you will open MainAvtivity.java class file and write the following code

Run the Application

Alt Tag Toolbar in android material design navigation

When you run the application and click on navigation image then a new activity will open. this activity have action bar as they main activity.In this activity have also a button in left side when user click on this button will  be move in mainActivity.

Alt Tag Toolbar in android material design navigation1

Conclusion

In this lecture we learn about Android Material design.First part we describe how can add Toolbar . Second part we describe how can Customize the Toolbar .Third part we describe how can add action in Toolbar bar. I hope you will understand this lecture.Thank you for reading this lecture Hope you got the idea.