Search code examples
androidcoordinator-layout

How to hide the searchbar as it starts


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.


Solution

  • 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>