title: How to add collapsing toolbar with fragment in a single activity
body: <h2>This is my MainActivity</h2>
  
  <pre><code>public class ProjectDetailsActivity extends AppCompatActivity {
  
      private static final String TAG = ProjectDetailsActivity.class.getSimpleName();
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
  
          super.onCreate(savedInstanceState);
  
          setContentView(R.layout.activity_container);
  
          if (savedInstanceState == null) {
              addFragment(new ProjectDetailsFragment(), false);
          }
  
          Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_detail);
          toolbar.setNavigationIcon(R.drawable.ic_action_back);
          setSupportActionBar(toolbar);
  
          FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
          fab.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  Snackbar.make(view, "Button Clicked", Snackbar.LENGTH_LONG)
                          .setAction("Action", null).show();
              }
          });
  
  
  
      }
  
      public void addFragment(Fragment f, boolean isAddToBack) {
  
          FragmentTransaction mFragmentTransaction = getSupportFragmentManager().beginTransaction();
          mFragmentTransaction.replace(R.id.fragment_container, f);
          if (isAddToBack) {
              mFragmentTransaction.addToBackStack(null);
          }
          mFragmentTransaction.commit();
      }
  
      @Override
      public void onBackPressed() {
  
          super.onBackPressed();
          overridePendingTransition(R.anim.abc_fade_in, R.anim.abc_fade_out);
      }
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          if(item.getItemId()==android.R.id.home){
              onBackPressed();
          }
          return super.onOptionsItemSelected(item);
      }
  </code></pre>
  
  <blockquote>
    <p>This my xml file</p>
  </blockquote>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:fitsSystemWindows="true"
      tools:context="com.example.abcd.scrollappdemo.ScrollingActivity"&gt;
  
      &lt;android.support.design.widget.AppBarLayout
          android:id="@+id/app_bar"
          android:layout_width="match_parent"
          android:layout_height="@dimen/toolbar_scrollable_image_height"
          android:fitsSystemWindows="true"
          android:theme="@style/AppTheme.AppBarOverlay"&gt;
  
          &lt;android.support.design.widget.CollapsingToolbarLayout
              android:id="@+id/toolbar_layout"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:fitsSystemWindows="true"
              app:contentScrim="?attr/colorPrimary"
              app:layout_scrollFlags="scroll|exitUntilCollapsed"
              &gt;
  
              &lt;ImageView
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:src="@drawable/title_bg" /&gt;
  
              &lt;TextView
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:layout_gravity="bottom|start"
                  android:text="Garden Residency II"
                  android:textColor="#ffffffff" /&gt;
  
              &lt;android.support.v7.widget.Toolbar
                  android:id="@+id/toolbar_detail"
                  android:layout_width="match_parent"
                  android:layout_height="?attr/actionBarSize"
                  app:layout_collapseMode="pin"
                  app:popupTheme="@style/AppTheme.PopupOverlay" /&gt;
  
          &lt;/android.support.design.widget.CollapsingToolbarLayout&gt;
      &lt;/android.support.design.widget.AppBarLayout&gt;
  
      &lt;include
          android:id="@+id/include_layout"
          layout="@layout/project_detail_content" /&gt;
  
      &lt;android.support.design.widget.FloatingActionButton
          android:id="@+id/fab"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_margin="@dimen/fab_margin"
          app:layout_anchor="@id/app_bar"
          app:layout_anchorGravity="bottom|end" /&gt;
  
  &lt;/android.support.design.widget.CoordinatorLayout&gt;
  </code></pre>
  
  <blockquote>
    <p>This is my fragment class`</p>
  </blockquote>
  
  <pre><code>public class ProjectDetailsFragment extends BaseFragment implements View.OnClickListener {
  
      private static final String TAG = ProjectDetailsFragment.class.getSimpleName();
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
  
          super.onCreate(savedInstanceState);
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  
          View mView = inflater.inflate(R.layout.fragment_details, container, false);
  
          mappingWidgets(mView);
  
          return mView;
      }
  
      private void mappingWidgets(View v) {
  
  
      }
  
      @Override
      public void onClick(View v) {
  
  
      }
  
      }
  </code></pre>
  
  <p>Error Log :</p>
  
  <pre><code>FATAL EXCEPTION: main
  java.lang.RuntimeException: Unable to start activity ComponentInfo{}:
  java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.Toolbar.setNavigationIcon(int)' on a null object reference at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
  at android.app.ActivityThread.-wrap11(ActivityThread.java)
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
  at android.os.Handler.dispatchMessage(Handler.java:102)
  at android.os.Looper.loop(Looper.java:148)
  at android.app.ActivityThread.main(ActivityThread.java:5417)
  at java.lang.reflect.Method.invoke(Native Method)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
  Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.Toolbar.setNavigationIcon(int)' on a null object reference
  at com.abc.xyz.abcActivity.onCreate(ProjectDetailsActivity.java:32)
  at android.app.Activity.performCreate(Activity.java:6237)
  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
  at android.app.ActivityThread.-wrap11(ActivityThread.java) 
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
  at android.os.Handler.dispatchMessage(Handler.java:102)
  at android.os.Looper.loop(Looper.java:148)
  at android.app.ActivityThread.main(ActivityThread.java:5417)
  at java.lang.reflect.Method.invoke(Native Method)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
  </code></pre>
  
  <blockquote>
    <p>Activity theme in Mainfest is - </p>
  </blockquote>
  
  <pre><code>@style/Apptheme.Noactionbar
  </code></pre>