title: Different implementation for a floating action button in each fragment of an activity
body: <p>This is regarding the issue of coordinating the behaviour of a Floating Action Button in an Activity which has 5 fragments in it.</p>
  
  <p>In my app, I have an Activity which houses a ViewPager and an xml defined with FloatingActionButton. The ViewPager contains  Fragments, and inside each Fragment there is a RecyclerView.On clicking floating action button i have implemented scrollToPosition(0). As i have implemented Floating ActionButton in the xml file of main activity ,scrollToPosition() works only in the last fragment on clicking floating action button.How do i overcome this so that on clicking floating button in any fragment the recycler view scrolls to top?  </p>
  
  <p>I have tried implementing floatingactionbutton in fragment layout file and it works completely fine.But the problem with this is floating action button wil be moving when i swipe from one fragment to another fragment.So  is there any way so that i can implement floatingactionbutton in the main activity xml file and still be able to achieve scrollToPosotion(0) in every fragment on clicking FloatingActionButton? Many thanks for any suggestions.</p>
  
  <p>The following is the xml file which contains floating action button.</p>
  
  <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:background="#f4f4f4"
  tools:context=".MainActivity"&gt;
  
  &lt;android.support.design.widget.AppBarLayout
      android:id="@+id/appbar"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:fitsSystemWindows="true"&gt;
  
      &lt;android.support.v7.widget.Toolbar
          android:id="@+id/tb_main"
          android:layout_width="match_parent"
          android:layout_height="?attr/actionBarSize"
          android:background="?attr/colorPrimary"
          android:elevation="0dp"
          android:fitsSystemWindows="true"
          app:layout_scrollFlags="scroll|enterAlways"
          app:popupTheme="@style/ThemeOverlay.AppCompat.Dark" /&gt;
  
      &lt;com.myapp.now.extras.SlidingTabLayout
          android:id="@+id/sl_tab"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:fitsSystemWindows="true"&gt;
  
      &lt;/com.myapp.now.extras.SlidingTabLayout&gt;
  
  &lt;/android.support.design.widget.AppBarLayout&gt;
  
  
  &lt;android.support.v4.view.ViewPager
      android:id="@+id/vp_tab"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      /&gt;
  
  
      &lt;android.support.design.widget.FloatingActionButton
      android:id="@+id/fab"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_gravity="bottom|right|end"
      android:layout_marginBottom="@dimen/fab_margin_bottom"
      android:layout_marginEnd="@dimen/fab_margin_right"
      android:layout_marginRight="@dimen/fab_margin_right"
      android:clickable="true"
      android:src="@mipmap/top_scroll"
      app:backgroundTint="@color/colorFAB"
      app:borderWidth="0dp"
      app:fabSize="normal" /&gt;
  </code></pre>
  
  <p></p>
  
  <p>The following is an xml file of a fragment</p>
  
  <pre><code>&lt;FrameLayout     xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  xmlns:app="http://schemas.android.com/apk/res-auto"&gt;
  &lt;android.support.v4.widget.SwipeRefreshLayout
      android:id="@+id/srl_swipe"
      android:layout_width="match_parent"
      android:layout_height="match_parent"&gt;
      &lt;android.support.v7.widget.RecyclerView
          android:id="@+id/rv_list"
          android:scrollbars="vertical"
          android:fadeScrollbars="true"
          android:layout_width="match_parent"
          android:layout_height="match_parent"/&gt;
  
  &lt;/android.support.v4.widget.SwipeRefreshLayout&gt;
  
  &lt;ProgressBar
      android:visibility="gone"
      android:layout_gravity="center"
      android:id="@+id/pbar"
      android:layout_width="40dp"
      android:layout_height="40dp" /&gt;
  </code></pre>
  
  <p></p>
  
  <p>The following is the implementation of floating action button in each fragment</p>
  
  <pre><code> fab = (android.support.design.widget.FloatingActionButton) view.findViewById(R.id.fab);
      fab.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
  
              LinearLayoutManager llm = (LinearLayoutManager) mRecyclerView.getLayoutManager();
              llm.scrollToPositionWithOffset(0, 0);
          }
      });
  </code></pre>