My HomeActivity extends AppCompatActivity that uses 2 tabs.
public class HomeActivity extends AppCompatActivity {
private SectionsPagerAdapter mSection
You can use addOnTabSelectedListener
method:
tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
viewPager.setCurrentItem(tab.getPosition());
if (tab.getPosition() == 0) {
toolBarTitle.setText("Tab one");
} else if (tab.getPosition() == 1) {
toolBarTitle.setText("Tab two");
} else {
toolBarTitle.setText("Tab three");
}
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
}
});