Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I change the android actionbar title and icon

People also ask

How can I change the color of the title bar in Android?

Just go to res/values/styles.edit the xml file to change the color of action bar.


This is very simple to accomplish

If you want to change it in code, call:

setTitle("My new title");
getActionBar().setIcon(R.drawable.my_icon);

And set the values to whatever you please.

Or, in the Android manifest XML file:

<activity android:name=".MyActivity" 
       android:icon="@drawable/my_icon" 
       android:label="My new title" />  

To enable the back button in your app use:

 getActionBar().setHomeButtonEnabled(true);
 getActionBar().setDisplayHomeAsUpEnabled(true);

The code should all be placed in your onCreate so that the label/icon changing is transparent to the user, but in reality it can be called anywhere during the activity's lifecycle.


To make a single icon be usable by all your action bars you can do this in your Android Manifest.

<application
    android:logo="@drawable/Image">

    ...

</application>

You just need to add these 3 lines of code. Replace the icon with your own icon. If you want to generate icons use this

getSupportActionBar().setHomeAsUpIndicator(R.drawable.icon_back_arrow);
getActionBar().setHomeButtonEnabled(true);
getActionBar().setDisplayHomeAsUpEnabled(true);

In Android 5.0 material design guidelines discourage the use of icon in actionBar

to enable it add the following code

getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setLogo(R.mipmap.ic_launcher);
getSupportActionBar().setDisplayUseLogoEnabled(true);

credit goes to author of this article