title: Title of Collapsing toolbar is not changing when setting dynamically?
body: <p>I have used viewpager for showing the data of per month. and I want to change the title of collapsing toolbar accroding to change in viewpager's page.
  Collapsing toolbar title only changes when scrolling up the toolbar.
  <img src="https://i.stack.imgur.com/nGpkQ.png" alt="enter image description here"></p>
  
  <p>my layout </p>
  
  <pre><code>&lt;android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      android:layout_width="match_parent"
      android:layout_height="match_parent"&gt;
  
      &lt;android.support.v4.widget.NestedScrollView
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          app:layout_behavior="@string/appbar_scrolling_view_behavior"&gt;
  
          &lt;LinearLayout
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:orientation="vertical"&gt;
  
              &lt;android.support.v4.view.ViewPager
                  android:id="@+id/view_pager"
                  android:layout_width="match_parent"
                  android:layout_height="@dimen/activity_history_view_pager_height" /&gt;
          &lt;/LinearLayout&gt;
      &lt;/android.support.v4.widget.NestedScrollView&gt;
  
      &lt;android.support.design.widget.AppBarLayout
          android:id="@+id/my_layout"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_alignParentTop="true"&gt;
  
          &lt;android.support.design.widget.CollapsingToolbarLayout
              android:id="@+id/collapsing_toolbar"
              android:layout_width="match_parent"
              android:layout_height="@dimen/activity_history_collapsing_toolbar_height"
              android:fitsSystemWindows="true"
              app:contentScrim="?attr/colorPrimary"
              app:layout_scrollFlags="scroll|exitUntilCollapsed"&gt;
  
              &lt;android.support.v7.widget.Toolbar
                  android:id="@+id/toolbar_flexible_space"
                  android:layout_width="match_parent"
                  android:layout_height="?attr/actionBarSize"
                  android:background="?attr/colorPrimary"
                  android:fitsSystemWindows="true"
                  android:minHeight="?attr/actionBarSize"
                  app:layout_collapseMode="pin"
                  app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                  app:theme="@style/ThemeOverlay.AppCompat.Light" /&gt;
          &lt;/android.support.design.widget.CollapsingToolbarLayout&gt;
  
          &lt;TextView
              android:id="@+id/txt_year"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_marginLeft="@dimen/activity_history_margin_left"
              android:layout_marginStart="@dimen/activity_history_margin_left"
              android:text="@string/activity_history_year"
              android:textColor="@color/white"
              android:textSize="@dimen/activity_history_text_size" /&gt;
  
          &lt;RelativeLayout
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:layout_marginBottom="@dimen/activity_history_margin_bottom"
              android:orientation="vertical"
              app:layout_scrollFlags="scroll"&gt;
  
              &lt;LinearLayout
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_alignParentEnd="true"
                  android:layout_alignParentRight="true"
                  android:layout_marginEnd="@dimen/activity_history_margin_right"
                  android:layout_marginRight="@dimen/activity_history_margin_right"
                  android:orientation="horizontal"&gt;
  
                  &lt;ImageView
                      android:id="@+id/img_leftBackArrow"
                      android:layout_width="@dimen/activity_history_arrow_size"
                      android:layout_height="@dimen/activity_history_arrow_size"
                      android:contentDescription="@string/content_description"
                      android:src="@drawable/previous_arrow" /&gt;
  
                  &lt;ImageView
                      android:id="@+id/img_rightBackArrow"
                      android:layout_width="@dimen/activity_history_arrow_size"
                      android:layout_height="@dimen/activity_history_arrow_size"
                      android:layout_marginLeft="@dimen/activity_history_arrow_size"
                      android:layout_marginStart="@dimen/activity_history_arrow_size"
                      android:contentDescription="@string/content_description"
                      android:src="@drawable/next_arrow" /&gt;
  
              &lt;/LinearLayout&gt;
  
  
          &lt;/RelativeLayout&gt;
  
      &lt;/android.support.design.widget.AppBarLayout&gt;
  
  &lt;/android.support.design.widget.CoordinatorLayout&gt;
  </code></pre>
  
  <p>In Activity</p>
  
  <pre><code>    /**
       * Lists History of the Tasks and it's status on the basis of Date
       */
      public class HistoryActivity extends BaseActivity implements ViewPager.OnPageChangeListener {
  
          @InjectView(R.id.toolbar_flexible_space)
          Toolbar toolbar;
  
          @InjectView(R.id.collapsing_toolbar)
          CollapsingToolbarLayout mCollapsingToolbar;
  
          @InjectView(R.id.view_pager)
          ViewPager viewPager;
  
          @InjectView(R.id.txt_year)
          TextView txtYear;
          int viewPagerSize = 0;
  
          ArrayList&lt;String&gt; taskAddedMonths;
  
          @OnClick({R.id.img_leftBackArrow, R.id.img_rightBackArrow})
          public void onClick(View v) {
              switch (v.getId()) {
                  case R.id.img_rightBackArrow:
                      moveForward();
                      break;
                  case R.id.img_leftBackArrow:
                      moveBackWard();
                      break;
  
              }
  
          }
  
          /**
           * move view pager page as accroding to clicking on backword arrow.
           */
          private void moveBackWard() {
              int currentPosition = viewPager.getCurrentItem();
              if (currentPosition &gt; 0) {
                  int nextPosition = currentPosition - 1;
                  viewPager.setCurrentItem(nextPosition);
                  mCollapsingToolbar.setTitle(getCollapsingToolbarTitle(taskAddedMonths.get(nextPosition)));
              }
          }
  
          /**
           * move view pager page as according to clicking on forward arrow.
           */
          private void moveForward() {
              int currentPosition = viewPager.getCurrentItem();
  
              if (currentPosition &lt; viewPagerSize-1) {
                  int nextPosition = currentPosition + 1;
                  if (viewPagerSize == 1) {
                      //do nothing
                  } else {
                      viewPager.setCurrentItem(currentPosition + 1);
                      mCollapsingToolbar.setTitle(getCollapsingToolbarTitle(taskAddedMonths.get(nextPosition)));
                  }
              }
          }
  
  
          @Override
          protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
  
              taskAddedMonths = DatabaseManager.getInstance(HistoryActivity.this).getAllMonths();
              viewPagerSize = taskAddedMonths.size();
  
              mCollapsingToolbar.setTitle(getCollapsingToolbarTitle(taskAddedMonths.get(0)));
              mCollapsingToolbar.setExpandedTitleColor(Color.WHITE);
              toolbar.setNavigationIcon(ContextCompat.getDrawable(this, R.drawable.ic_backarrow));
  
              viewPager.setAdapter(new ViewPagerAdapter(HistoryActivity.this, DatabaseManager.getInstance(HistoryActivity.this).getAllMonths()));
              viewPager.addOnPageChangeListener(this);
  
          }
  
          @Override
          public int getLayoutId() {
              return R.layout.activity_history;
          }
  
          @Override
          public Toolbar getToolbar() {
              return toolbar;
          }
  
          @Override
          public boolean onCreateOptionsMenu(Menu menu) {
              // Inflate the menu; this adds items to the action bar if it is present.
              getMenuInflater().inflate(R.menu.menu_history, menu);
              return true;
          }
  
          @Override
          public boolean onOptionsItemSelected(MenuItem item) {
              // Handle action bar item clicks here. The action bar will
              // automatically handle clicks on the Home/Up button, so long
              // as you specify a parent activity in AndroidManifest.xml.
              int id = item.getItemId();
              //noinspection SimplifiableIfStatement
              if (id == android.R.id.home) {
                  onBackPressed();
              }
              return super.onOptionsItemSelected(item);
          }
  
          /**
           * get the name of month with concatenating History as like this{May History};
           *
           * @param month
           * @return
           */
          private String getCollapsingToolbarTitle(String month) {
              return month + " " + "History";
          }
  
          @Override
          public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
  
          }
  
          @Override
          public void onPageSelected(int position) {
  /******************* what i have done*******************/
              //change the title of collapsing toolbar accroding to change in page of viewpager
              mCollapsingToolbar.setTitle(getCollapsingToolbarTitle(taskAddedMonths.get(position)));
          }
  
          @Override
          public void onPageScrollStateChanged(int state) {
  
          }
      }
  </code></pre>