简体   繁体   中英

Hiding Toolbar in tabbed activity with fragment with ScrollView in its ViewPager

I want to hide toolBar when scroll View in fragment of ViewPager is scrolled but when i scroll only scrollView's part is being scrolled (with toolbar in its place).

consider, when I scroll on tablayout (header part, id- tabs) it hides the toolbar

<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"
    tools:context=".MainActivity">

    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">


        <Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:elevation="5dp"
            app:layout_scrollFlags="scroll|enterAlways|snap" />


        <com.google.android.material.tabs.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="?attr/colorPrimary"
            app:tabIndicatorColor="@android:color/white" />
    </com.google.android.material.appbar.AppBarLayout>

   <androidx.viewpager.widget.ViewPager
        android:id="@+id/view_pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>

and in My java file is

    Toolbar toolbar = findViewById(R.id.toolbar);      

    toolbar.setTitle("304 Pramukh");

and my fragments Xml file is

<FrameLayout 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"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context=".Fragments.CommunityFragment">

    <!-- TODO: Update blank fragment layout -->
    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

             <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/rv_family"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
       </LinearLayout>
    </ScrollView>
</FrameLayout>```

This needed only one minor change, Just replaced scroll View with Nested scroll view...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM