Currently it just displays the name of the application and I want it to display something custom and be different for each screen in my app.
For example: my home screen could say 'page1' in the action bar while another activity that the app switches to could have 'page2' in that screens action bar.
You can define your title programatically using
setTitle
within yourActivity
, this method can accept either aString
or an ID defined in yourvalues/strings.xml
file. Example:Inside Activity.onCreate() callback or in the another place where you need to change title:
The best way to change the action bar name is to go to the AndroidManifest.xml and type this code.
Little bit older but had the same problem. I did it like this:
strings.xml
<string name="title_awesome_app">My Awesome App</string>
and make sure you set this in your AndroidManifest.xml:
it's easy and you don't have to worry about null-references and other stuff.
You can define the label for each activity in your manifest file.
A normal definition of a activity looks like this:
Where title text should be replaced by the id of a string resource for this activity.
You can also set the title text from code if you want to set it dynamically.
with this line the title is set to the city of a specific adress in the oncreate method of my activity.