3

I have an topbar for title and icons and a searchbar. When I scroll up both of that hiding and its ok. But I want to hide searchbar when activity start first and show when scroll down first. (Like ios whatsapp application, default is hidden)

enter image description here

<androidx.coordinatorlayout.widget.CoordinatorLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">


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


                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="56dp"
                    app:layout_scrollFlags="scroll">

                    //...

                </RelativeLayout>

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

                    //...

                </RelativeLayout>

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

            <androidx.recyclerview.widget.RecyclerView/>


        </androidx.coordinatorlayout.widget.CoordinatorLayout>

Is there any scrollflags for it. Thanks for any help.

Sorry for my terrible english.

6155031
  • 3,352
  • 4
  • 19
  • 49

2 Answers2

1

add app:expanded="false" to appbarlayout. And use only one bar inside in it.

<RelativeLayout>
<RelativeLayout
    android:layout_height="56dp"
    android:layout_width="match_parent"
    app:layout_scrollFlags="scroll">

    //...

</RelativeLayout>
<androidx.coordinatorlayout.widget.CoordinatorLayout
    android:layout_height="match_parent"
    android:layout_width="match_parent">


    <com.google.android.material.appbar.AppBarLayout
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        app:expanded="false">

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

            //...

        </RelativeLayout>

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

    <androidx.recyclerview.widget.RecyclerView />


</androidx.coordinatorlayout.widget.CoordinatorLayout>
0

Use Collapsing ToolBar as shown Code

<androidx.coordinatorlayout.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <!-- Scrollable view here -->

      <com.google.android.material.appbar.AppBarLayout
          android:layout_width="match_parent"
          android:layout_height="@dimen/tall_toolbar_height">

        <com.google.android.material.appbar.CollapsingToolbarLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleGravity="top"
            app:layout_scrollFlags="scroll|exitUntilCollapsed|snap">

          <androidx.appcompat.widget.Toolbar
              android:layout_width="match_parent"
              android:layout_height="?attr/actionBarSize"
              app:layout_collapseMode="pin"/>
        </com.google.android.material.appbar.CollapsingToolbarLayout>
      </com.google.android.material.appbar.AppBarLayout>
    </androidx.coordinatorlayout.widget.CoordinatorLayout>
Pawan Soni
  • 650
  • 5
  • 18