Categories
木有技术

How to change the android actionbar title and icon | 如何设置ActionBar的图标和文字

Source : http://stackoverflow.com/questions/14483393/how-do-i-change-the-android-actionbar-title-and-icon
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);

In XML:



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

Leave a Reply

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

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