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
how to change a title of the activity?
795 views Asked by Srinath Gopathi At
5
There are 5 answers
0
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
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.
You can set the title in code like this:
You can also do it in xml like this: