Toolbar – add the up button


I am trying to use the Toolbar instead of the ActionBar, but I can’t figure out how to add the up button to return to the previous activity.
I couldn’t find any method that could relate to it.

How do I add the up button?


I guess what you are looking for is something like this:

Toolbar toolbar = (Toolbar) findViewById(;

Or in case of using in Fragment:

Toolbar toolbar = (Toolbar) view.findViewById(;
((ActionBarActivity) getActivity()).setSupportActionBar(toolbar);
((ActionBarActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true);

This will show up your Action Bar inside of your toolbar, but don’t worry everything will fit together well. The last you have to do if you dont want any shadow under your action bar or any background of it is change your theme in vaules/styles.xml.

<style name="AppThmeme.Base" parent="Theme.AppCompat.NoActionBar">

Answered By – Jan Omacka

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published