0

I need to hide toolBar(Header) and keep tapLayout in the top when scroll viewPager

viewPager will contain fragment contain a RecyclerView

tell me if there is another way to code it

if there is a way to fix this code this is the best for me

My layout design

Here is my XML code

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">


    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true">

        <com.google.android.material.appbar.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:contentScrim="@color/white"
            app:layout_collapseMode="parallax"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <include
                android:id="@+id/homeHeader"
                layout="@layout/user_profile_header" />


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


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


    <LinearLayout
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">


        <!--Tab-->
        <com.google.android.material.tabs.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabGravity="fill"
            app:tabMode="fixed" />


        <!--ViewPager-->
        <androidx.viewpager.widget.ViewPager
            android:id="@+id/viewpager"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </LinearLayout>


</androidx.coordinatorlayout.widget.CoordinatorLayout>
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
  • Do u want to hide toolbar (may be present Inside ur header) or header layout completely.??? – Mohamed Mohaideen AH Feb 25 '20 at 15:55
  • i need to hide toolBar when i scrolling RecyclerView in a fragment in viewPager – exactly like instagram profile page (and i need to keep the tabs in the top of activity) – Saeed Damra Feb 25 '20 at 16:09
  • 4
    Does this answer your question? [Hiding/Showing the toolbar when fragment in the tabs is scrolled](https://stackoverflow.com/questions/32069521/hiding-showing-the-toolbar-when-fragment-in-the-tabs-is-scrolled) – Mohamed Mohaideen AH Feb 25 '20 at 16:13

1 Answers1

1

getSupportActionBar().hide();

Place this part of code in your oncreate

Akash Jp
  • 162
  • 1
  • 10