Add home button on action bar

To add home button in action bar write some code in onCreate section.

Write first code for enable button in action bar.



After that write code for set home button in action bar.



Note :- ic_home_white is id of icon. can change image as you want.

After that write some more code for performe any action.

public boolean onOptionsItemSelected(MenuItem item){
switch (item.getItemId()){
//write here some action
return super.onOptionsItemSelected(item);

Mostly we create AppCompat application and in this type application the code given up don’t work to modify action bar. so what should you do for modify action bar in AppCompat type apps.

Here is solution. write some code before write action bar enable and set home button codes.

Code ab = getSupportActionBar();

Now write this code. its same code given up but it’s now work in AppCompat apps.


To modify action bar in sketchwere write same code in add source directly and also apply same condition.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.