Hide action bar, but show when pulled down

2019-08-17 17:38发布

问题:

I have an action bar set up and it works great. I'd like to have it so that it is hidden until the user does something like pull down from the top of the screen, and then show it.

I can't find any resources which discuss doing this.

回答1:

You can also use Collapsing Toolbar

<android.support.design.widget.AppBarLayout
       android:layout_width="match_parent"
       android:layout_height="180dp"
       android:theme="@style/ThemeOverlay.AppCompat.Dark">

       <android.support.design.widget.CollapsingToolbarLayout
           android:id="@+id/collapse_toolbar"
           android:layout_width="match_parent"
           android:layout_height="match_parent"
           app:layout_scrollFlags="scroll|exitUntilCollapsed">

           <android.support.v7.widget.Toolbar
               android:id="@+id/toolbar"
               android:layout_width="match_parent"
               android:layout_height="?attr/actionBarSize"
               app:layout_collapseMode="pin" />
       </android.support.design.widget.CollapsingToolbarLayout>
   </android.support.design.widget.AppBarLayout>


回答2:

You can toggle its visiblity using OnClickListener on layout or if you have some layout that is scrolled by the user then you can experiment with OnScrollChangeListener.