How to Add Back Button to Toolbar Android

In this post you will learn how to add the back button to toolbar android, We use the toolbar back button to

go back in our application.


create a new project in android studio


First of all we need to add second activity in our project like below

add back button to toolbar android


Open activity_second.xml and paste the below code

Now we need some changes in our MainActivity

So open activity_main.xml and paste the below code


In add this code


Now the main thing comes open AndroidManifest.xml

and make the following changes to add back button to toolbar android


Run your app and try to open second activity

on button click and in second activity you will see a back arrow

on toolbar, now click on back arrow then you will come back

to MainActivity because in Manifest we added MainActivity as

a parent of SecondActivity.


If you have any question ask me in the comments section.

Written by Hilal Ahmad

Leave a Reply

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