Reputation: 1903
I am following this tutorial in order to set up some tabbed activities. All is going fine until I try change the main app title at the top of the screen. What I want to happen is change the title to reflect the title of the open tab.
I am quite new to fragments so this is causing some trouble. I am able to change the title for the activities but when ever I try change the fragments it sets the title the same for all tabs and not individually.
From my understanding the fragments are launched from the main activity and replace the current view, i just can seem to figure out where the tutorial is changing the title per fragment
Upvotes: 1
Views: 1059
Reputation: 25312
Try below code:
((AppCompatActivity) getActivity()).getSupportActionBar().setTitle("Toolbar Title String");
Upvotes: 1
Reputation: 125
//Here created a string array for store one or more titles
String[] tabsTitles = {"Title 1", "Title 2", "Title 3"};
viewpager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageSelected(int position) {
// TODO Auto-generated method stub
//here in array pass position as an index value for get title and set that
actionBar.setTitle(tabsTitles[position]);
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
// TODO Auto-generated method stub
}
@Override
public void onPageScrollStateChanged(int pos) {
// TODO Auto-generated method stub
}
});
Upvotes: 2
Reputation: 2668
if i understood probably, you want to change title of that activity right ? if so just type
setTitle("My Title");
Upvotes: 0