title: setTitle not working Android
body: <p>I created a sliding tab activity and I am trying to dynamically change the title of the app bar. but what ever i do it doesnt seem to work! here is my MainActivity.java:</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
  
  ViewPager mPager;
  SlidingTabLayout mTabs;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
  
      getSupportActionBar().setDisplayShowHomeEnabled(true);
  
  
      mPager = (ViewPager) findViewById(R.id.pager);
  
      mPager.setAdapter(new MyPagerAdapter(getSupportFragmentManager()));
  
      mTabs = (SlidingTabLayout) findViewById(R.id.tabs);
  
      mTabs.setCustomTabView(R.layout.custom_tab_view, R.id.tabText);
  
      mTabs.setDistributeEvenly(true);
  
      mTabs.setSelectedIndicatorColors(getResources().getColor(R.color.colorAccent));
      mTabs.setBackgroundColor(getResources().getColor(R.color.colorPrimary));
  
      mTabs.setViewPager(mPager);
  
  }
  
  class MyPagerAdapter extends FragmentPagerAdapter {
  
      int tabIcons[] = {R.drawable.ic_events, R.drawable.ic_clients, R.drawable.ic_history};
      String[] tabText = getResources().getStringArray(R.array.tabs);
  
      public MyPagerAdapter(FragmentManager fm) {
          super(fm);
      }
  
      @Override
      public Fragment getItem(int position) {
  
          switch (position){
              case 0:
                  getSupportActionBar().setTitle("Events");
                  EventsFragment eventsFragment = EventsFragment.getInstance(position);
                  return eventsFragment;
  
              case 1:
                  getSupportActionBar().setTitle("Clients");
                  ClientsFragment clientsFragment = ClientsFragment.getInstance(position);
                  return clientsFragment;
  
              case 2:
                  getSupportActionBar().setTitle("History");
                  HistoryFragment historyFragment = HistoryFragment.getInstance(position);
                  return historyFragment;
  
              default:
                  getSupportActionBar().setTitle("Events");
                  EventsFragment defaultFragment = EventsFragment.getInstance(position);
                  return defaultFragment;
  
          }
  
      }
  
      @Override
      public CharSequence getPageTitle(int position) {
  
          Drawable drawable = getResources().getDrawable(tabIcons[position]);
  
          drawable.setBounds(0,0,64,64);
  
          ImageSpan imageSpan = new ImageSpan(drawable);
  
          SpannableString spannableString = new SpannableString(" ");
  
          spannableString.setSpan(imageSpan, 0, spannableString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
  
          return spannableString;
      }
  
      @Override
      public int getCount() {
          return 3;
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I have also tried to set the title of the app bar in the <code>onCreate</code> method using:</p>
  
  <pre><code> getSupportActionBar().setTitle("Test");
  </code></pre>
  
  <p>which doesn't work either.</p>
  
  <p>How can I solve this? Thanks!</p>