1

The latest Google Newsstand App features an ActionBar and ViewPager tab bar which slowly eases out the top of the screen when the list below it is scrolled down. Importantly, it eases out at the same speed the list is scrolled. When the list is scrolled upwards the ActionBar eases back onto the screen, again at the same speed the list is scrolled.

I am not referring to the ActionBar hide() and show() methods, instead I want to know how to hide and show the ActionBar at the same rate the list below it is scrolled.

How is this achieved? All attempts at finding a documented solution have proven unsuccessful so any help would be appreciated.

Milo
  • 1,017
  • 3
  • 16
  • 22

1 Answers1

2

Short Answer

Create a Fragment subclass that serves as an ActionBar replacement. Use an OnScrollListener to update the fragment's view's translationY after scroll events.

Long Answer

After digging around the ActionBar source code, it seems that there is no public method for accessing the ActionBar container view. But where there's a will, there's a way.

You can grab a reference to the Action Bar's view using the following:

int resId = getResources().getIdentifier("action_bar_container", "id", "android");
View actionBarContainer = findViewById(resId);

Disclaimer: action_bar_container is a private ID, so it's subject to Google's whims. Use at your own risk.

Once you have the Action Bar's view, you can animate it however you'd like.

I hacked together a semi-functional example if you're interested.

Hope this helps!

Community
  • 1
  • 1
bmat
  • 2,084
  • 18
  • 24
  • That's incredibly good of you to provide a solution like that, thanks very much. As you said, I'll have to make a decision whether relying on action_bar_container not being changed in the future is worth the risk. Thanks. – Milo Oct 05 '14 at 10:04
  • I need to do a puch out/pull in action bar tabs.after imported that github,I can't see any java file inside src. can you check it and tell me. – Stephen Nov 25 '14 at 04:33