how to change a title of the activity?

800 views Asked by At

How do I change the title of the activity? as of now it just displays the title of the program and i am wanting it to display something of my choosing and be different for each page/activity in my app i.e. my home page could say frog(1/17) in the title while another activity that the app switches to could have frog(2/17) in that title by using on click event or by using butt

5

There are 5 answers

2
Scott Helme On

You can set the title in code like this:

setTitle("Some Title");

You can also do it in xml like this:

android:label="Some Title"
android:label="@strings/someTitle"
0
user1288005 On

You change title of an Activity programmatically by following code:

getActionBar.setTitle("Your_Activity_Name");
0
Luke Taylor On

If I understand you correctly, you would like something dynamic that changes the title (page count) when the button is pressed?

I would suggest the following:

private static int pageCount = 1; // global variable in class. Default page = 1

onCreate() {
setPage(pageCount); // Set the title for the first time

}

// When your button is clicked
private static onButton() {
pageCount++; // Increment page count by one
setPage(pageCount); // set the new title


}

private static setPage(int page) {
setTitle("frog(" + page + "/17)");

}

I hope this helps.

0
Yunfei Tang On

you can find result in android sdk sample ApiDemos, in section App -> Activity -> Custom Title

0
Armando Aceituno On

I just looked for the "values" folder inside the RES directory. There, you see a file named strings.xml. Inside that file, you find the values for all the titles of the activities. Look for the activity you want to change and presto! Example: The activity I wanted to change was "news" and the title I needed was "Here". I found this value: Central

So I changed it to this: Here

It gave me no trouble.