0

How do I hide the ActionBar as a user scrolls down a View?

I just created a sample activity from Android Studio's default "Tabbed Activity" using navigation style "Action Bar Tabs (with ViewPager". From there, if a user swipes down one of the tabs, how can I implement that effect of hiding the ActionBar and then pulling it back down when the user scrolls up? (Just like Google Play app does).

EDIT:

One of the tabs has a RecyclerView with some Views inside. It scrolls vertically. So you can read this as: how to hide the ActionBar as I scroll down this RecyclerView?

EDIT 2:

Visually, I'm trying to achieve this:

As the user scrolls down, ActionBar hides itself

Washington A. Ramos
  • 874
  • 1
  • 8
  • 25
  • possible duplicate of [Hiding the ActionBar on RecyclerView/ListView onScroll](http://stackoverflow.com/questions/13559275/hiding-the-actionbar-on-recyclerview-listview-onscroll) – Jared Burrows Apr 19 '15 at 19:15

1 Answers1

0

try this

getSupportActionBar.hide();  // if it extends action bar activity

or

getActionBar.hide();
Konrad Krakowiak
  • 12,285
  • 11
  • 58
  • 45
Shahbaz Hashmi
  • 2,631
  • 2
  • 26
  • 49
  • I didn't test the code, but how would I know when to use this? I mean, how do I know if the user did scroll down enough to hide the ActionBar? – Washington A. Ramos Apr 19 '15 at 18:08
  • I don't know what are you trying to do. But you can detect scroll by using setOnScrollListener(). – Shahbaz Hashmi Apr 19 '15 at 18:18
  • I've added a image trying to show what I'm trying to achieve, please try looking at it. – Washington A. Ramos Apr 19 '15 at 18:54
  • Get the vertical position of your scrollview by using getTranslationY() in setOnScrollListener() method. If (position changes) getTranslationY() is greater than the height of your action bar then execute getActionBar.hide(). If it doesn't work, try googling for these methods you will get the solution. – Shahbaz Hashmi Apr 19 '15 at 19:38