How to hide ActionBar while scrolling ListView in android?

后端 未结 4 620
南旧
南旧 2020-12-10 01:23

I need to create a GUI with a ListView and an ActionBar which will hide when scrolling down and when scrolling up it must reappear.

The foll

4条回答
  •  忘掉有多难
    2020-12-10 02:04

    Use [CoordinatorLayout]:https://developer.android.com/reference/android/support/design/widget/CoordinatorLayout.html, which allow co-oridanation among child views. it's like, act(AppBarLayout->scrolling) on some view when there is a behaviour observed(ListView->scroll) in another view.

    1. Make Listview nestedScrollingEnabled, works for >API 21

      android:nestedScrollingEnabled="true"
      
    2. Trigger layout behaviour to appbar scrolling.

      android:nestedScrollingEnabled="true"
      app:layout_behavior="@string/appbar_scrolling_view_behavior"
      
    3. Any layout(ToolBar/TabLayout/any), which is required to show-hide/scroll, place it inside AppBarLayout, and enabled scroll flag.

      app:layout_scrollFlags="scroll|enterAlways"
      

提交回复
热议问题