title: fragment of fragments toolbar title setting
body: <p>I have one Activity and lots of fragments switch between this Activity, i set the toolbar title just in this Activity , like this :
  this Activity:</p>
  
  <pre><code>@Override
  public void onClick(View view) {
      int id = view.getId();
      if (id == R.id.logIn){
          switchFragment(LogInFragment.newInstance());
          //when i switch fragment , i change the tile by this code
          toolbar.setTitle(R.string.pageLogIn);
          drawerLayout.closeDrawer(GravityCompat.START);
      }
      if (id == R.id.singUp){
          switchFragment(SignUp.newInstance());
          toolbar.setTitle(R.string.singUp);
          drawerLayout.closeDrawer(GravityCompat.START);
      }
  }
  
  private void switchFragment(Fragment fragment) {
      FragmentManager manager = getActivity().getSupportFragmentManager();
      FragmentTransaction transaction = manager.beginTransaction();
      transaction.replace(R.id.mainFrame, fragment, null);
      //transaction.addToBackStack(null);
      transaction.commit();
  }
  </code></pre>
  
  <p>and this my Activity layout:</p>
  
  <pre><code>&lt;android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      android:id="@+id/drawerLayout"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:context="com.example.user.taiwandigestionsociety_v11.MainActivity"&gt;
  
  
      &lt;android.support.design.widget.AppBarLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:background="#FFFFFF"&gt;
  
  
  
          &lt;android.support.v7.widget.Toolbar
              android:id="@+id/toolBar"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              app:theme="@style/ToolBarStyle"
              android:background="@drawable/actionbar"&gt;
          &lt;/android.support.v7.widget.Toolbar&gt;
  
          &lt;FrameLayout
              android:id="@+id/mainFrame"
              android:layout_gravity="end"
              android:layout_width="match_parent"
              android:layout_height="match_parent"&gt;
  
          &lt;/FrameLayout&gt;
  
      &lt;/android.support.design.widget.AppBarLayout&gt;
  
  
      &lt;android.support.design.widget.NavigationView
          android:id="@+id/nav_view"
          android:layout_width="wrap_content"
          android:layout_height="match_parent"
          android:layout_gravity="start"
          android:background="@android:color/transparent"
          android:fitsSystemWindows="true"
          app:headerLayout="@layout/nav_header"&gt;
      &lt;/android.support.design.widget.NavigationView&gt;
  
  
  &lt;/android.support.v4.widget.DrawerLayout&gt;
  </code></pre>
  
  <p>My question is one of fragments has a button that it will switch to new fragment, i can't switch the toolbar title by the Activity java .</p>
  
  <p>I try another way to set the function to call the Activity switch function, the app will crash .</p>
  
  <p>I try like this:</p>
  
  <pre><code>public class Welcome extends Fragment implements View.OnClickListener {
      @Override
      public void onClick(View view) {
          int id = view.getId();
          if (id == R.id.welcomeLogin){
              MainActivity mainActivity=new MainActivity();
              mainActivity.switchFragment(ActivityHomePage.newInstance());
          }
      }
  }
  </code></pre>
  
  <p>How can i set the fragment toolbar title like those fragments ?</p>