【问题标题】:How to hide the searchbar as it starts如何在启动时隐藏搜索栏
【发布时间】:2019-12-01 09:36:30
【问题描述】:

我有一个标题和图标的顶部栏和一个搜索栏。当我向上滚动隐藏和它的确定。但是我想在活动首先开始时隐藏搜索栏,并在首先向下滚动时显示。 (和ios whatsapp应用一样,默认是隐藏的)

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

是否有任何滚动标志。感谢您的帮助。

对不起我糟糕的英语。

【问题讨论】:

    标签: android coordinator-layout


    【解决方案1】:

    将 app:expanded="false" 添加到 appbarlayout。并且在里面只使用一个酒吧。

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

    【讨论】:

      【解决方案2】:

      使用折叠工具栏如图代码

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

      【讨论】:

        猜你喜欢
        • 2020-04-11
        • 2016-10-31
        • 1970-01-01
        • 2021-03-12
        • 2022-01-08
        • 1970-01-01
        • 2018-05-16
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多