How to hide toolbar when scrolling on Fragment












1














I have a main activity:



    <?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

<include layout="@layout/toolbar" />

</com.google.android.material.appbar.AppBarLayout>

<FrameLayout
android:id="@+id/frameInicio"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/adView"
android:layout_alignParentStart="true"
android:layout_marginTop="?android:attr/actionBarSize"
android:orientation="horizontal" />

<com.google.android.gms.ads.AdView xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/navigation"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:gravity="center"
android:visibility="visible"
ads:adSize="SMART_BANNER"
ads:adUnitId="example" />


<com.ittianyu.bottomnavigationviewex.BottomNavigationViewEx
android:id="@+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="?android:attr/windowBackground"
app:menu="@menu/bottom_navigation" />

</RelativeLayout>

</androidx.coordinatorlayout.widget.CoordinatorLayout>


In FrameLayout "frameInicio" I load a fragment with this:



 <RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipeApuestas"
android:layout_width="match_parent"
android:layout_height="match_parent">

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerApuestas"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</RelativeLayout>


I want when scroll in RecyclerView in Fragment, Toolbar of main_activity_layout, hides. How can I do?



I tried with recycler in the same activity, but i don't wanna do this, I want with diferent fragment, because I have a bottom navigation to control diferent fragment.



Thank you so much.










share|improve this question



























    1














    I have a main activity:



        <?xml version="1.0" encoding="utf-8"?>
    <androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.google.android.material.appbar.AppBarLayout
    android:id="@+id/appBar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?attr/colorPrimary"
    android:fitsSystemWindows="true"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <include layout="@layout/toolbar" />

    </com.google.android.material.appbar.AppBarLayout>

    <FrameLayout
    android:id="@+id/frameInicio"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@+id/adView"
    android:layout_alignParentStart="true"
    android:layout_marginTop="?android:attr/actionBarSize"
    android:orientation="horizontal" />

    <com.google.android.gms.ads.AdView xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:id="@+id/adView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_above="@+id/navigation"
    android:layout_centerInParent="true"
    android:layout_gravity="center"
    android:gravity="center"
    android:visibility="visible"
    ads:adSize="SMART_BANNER"
    ads:adUnitId="example" />


    <com.ittianyu.bottomnavigationviewex.BottomNavigationViewEx
    android:id="@+id/navigation"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:background="?android:attr/windowBackground"
    app:menu="@menu/bottom_navigation" />

    </RelativeLayout>

    </androidx.coordinatorlayout.widget.CoordinatorLayout>


    In FrameLayout "frameInicio" I load a fragment with this:



     <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
    android:id="@+id/swipeApuestas"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <androidx.recyclerview.widget.RecyclerView
    android:id="@+id/recyclerApuestas"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
    </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
    </RelativeLayout>


    I want when scroll in RecyclerView in Fragment, Toolbar of main_activity_layout, hides. How can I do?



    I tried with recycler in the same activity, but i don't wanna do this, I want with diferent fragment, because I have a bottom navigation to control diferent fragment.



    Thank you so much.










    share|improve this question

























      1












      1








      1







      I have a main activity:



          <?xml version="1.0" encoding="utf-8"?>
      <androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      android:id="@+id/main_content"
      android:layout_width="match_parent"
      android:layout_height="match_parent">

      <RelativeLayout
      android:layout_width="match_parent"
      android:layout_height="match_parent">

      <com.google.android.material.appbar.AppBarLayout
      android:id="@+id/appBar"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:background="?attr/colorPrimary"
      android:fitsSystemWindows="true"
      android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

      <include layout="@layout/toolbar" />

      </com.google.android.material.appbar.AppBarLayout>

      <FrameLayout
      android:id="@+id/frameInicio"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:layout_above="@+id/adView"
      android:layout_alignParentStart="true"
      android:layout_marginTop="?android:attr/actionBarSize"
      android:orientation="horizontal" />

      <com.google.android.gms.ads.AdView xmlns:ads="http://schemas.android.com/apk/res-auto"
      android:id="@+id/adView"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_above="@+id/navigation"
      android:layout_centerInParent="true"
      android:layout_gravity="center"
      android:gravity="center"
      android:visibility="visible"
      ads:adSize="SMART_BANNER"
      ads:adUnitId="example" />


      <com.ittianyu.bottomnavigationviewex.BottomNavigationViewEx
      android:id="@+id/navigation"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_alignParentBottom="true"
      android:background="?android:attr/windowBackground"
      app:menu="@menu/bottom_navigation" />

      </RelativeLayout>

      </androidx.coordinatorlayout.widget.CoordinatorLayout>


      In FrameLayout "frameInicio" I load a fragment with this:



       <RelativeLayout
      android:layout_width="match_parent"
      android:layout_height="match_parent">

      <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
      android:id="@+id/swipeApuestas"
      android:layout_width="match_parent"
      android:layout_height="match_parent">

      <androidx.recyclerview.widget.RecyclerView
      android:id="@+id/recyclerApuestas"
      android:layout_width="match_parent"
      android:layout_height="match_parent" />
      </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
      </RelativeLayout>


      I want when scroll in RecyclerView in Fragment, Toolbar of main_activity_layout, hides. How can I do?



      I tried with recycler in the same activity, but i don't wanna do this, I want with diferent fragment, because I have a bottom navigation to control diferent fragment.



      Thank you so much.










      share|improve this question













      I have a main activity:



          <?xml version="1.0" encoding="utf-8"?>
      <androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      android:id="@+id/main_content"
      android:layout_width="match_parent"
      android:layout_height="match_parent">

      <RelativeLayout
      android:layout_width="match_parent"
      android:layout_height="match_parent">

      <com.google.android.material.appbar.AppBarLayout
      android:id="@+id/appBar"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:background="?attr/colorPrimary"
      android:fitsSystemWindows="true"
      android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

      <include layout="@layout/toolbar" />

      </com.google.android.material.appbar.AppBarLayout>

      <FrameLayout
      android:id="@+id/frameInicio"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:layout_above="@+id/adView"
      android:layout_alignParentStart="true"
      android:layout_marginTop="?android:attr/actionBarSize"
      android:orientation="horizontal" />

      <com.google.android.gms.ads.AdView xmlns:ads="http://schemas.android.com/apk/res-auto"
      android:id="@+id/adView"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_above="@+id/navigation"
      android:layout_centerInParent="true"
      android:layout_gravity="center"
      android:gravity="center"
      android:visibility="visible"
      ads:adSize="SMART_BANNER"
      ads:adUnitId="example" />


      <com.ittianyu.bottomnavigationviewex.BottomNavigationViewEx
      android:id="@+id/navigation"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_alignParentBottom="true"
      android:background="?android:attr/windowBackground"
      app:menu="@menu/bottom_navigation" />

      </RelativeLayout>

      </androidx.coordinatorlayout.widget.CoordinatorLayout>


      In FrameLayout "frameInicio" I load a fragment with this:



       <RelativeLayout
      android:layout_width="match_parent"
      android:layout_height="match_parent">

      <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
      android:id="@+id/swipeApuestas"
      android:layout_width="match_parent"
      android:layout_height="match_parent">

      <androidx.recyclerview.widget.RecyclerView
      android:id="@+id/recyclerApuestas"
      android:layout_width="match_parent"
      android:layout_height="match_parent" />
      </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
      </RelativeLayout>


      I want when scroll in RecyclerView in Fragment, Toolbar of main_activity_layout, hides. How can I do?



      I tried with recycler in the same activity, but i don't wanna do this, I want with diferent fragment, because I have a bottom navigation to control diferent fragment.



      Thank you so much.







      android hide toolbar






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 19 '18 at 14:40









      Traif

      72119




      72119
























          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53376965%2fhow-to-hide-toolbar-when-scrolling-on-fragment%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53376965%2fhow-to-hide-toolbar-when-scrolling-on-fragment%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          MongoDB - Not Authorized To Execute Command

          in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

          How to fix TextFormField cause rebuild widget in Flutter