user4888414
user4888414

Reputation:

Android actionbar autohide

Is there an easy way to autohide the Actionbar? Similar to the way that the url bar in the Google Chrome app disappears when the user scrolls down, but then reappears when the user scrolls back up.

Upvotes: 1

Views: 335

Answers (2)

savepopulation
savepopulation

Reputation: 11921

It's name "Quick Return Pattern" You can find some useful libraries for this ux pattern from here: https://android-arsenal.com/tag/136

And you can find more details about this pattern from here: https://plus.google.com/+RomanNurik/posts/1Sb549FvpJt

I can post an example of qucik return pattern for a Listview with a quick return header. You can change it for ScrollView

yourListView.setOnScrollListener(new AbsListView.OnScrollListener() {
         @SuppressLint("NewApi")
         @Override
         public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            int scrollOffset = 0;
            float transitionY;

            if (firstVisibleItem > 0) {
               scrollOffset += headerHeight;
               if (firstVisibleItem > 1) {
                  scrollOffset += (firstVisibleItem - 1) * cellHeight;
               }
            }

            if (yourListView.getChildCount() > 0) {
               scrollOffset += -yourListView.getChildAt(0).getTop();
               scrollOffset = -scrollOffset;
            }

            float scrollDelta = scrollOffset - prevOffset;
            float nextY = mQuickReturnView.getY() + scrollDelta;

            if (nextY < minRawY) {
               transitionY = minRawY;
            }
            else if (nextY > qReturnDelta) {
               transitionY = qReturnDelta;
            }
            else {
               transitionY = nextY;
            }

            mQuickReturnView.setY(transitionY);
            prevOffset = scrollOffset;
         }

         @Override
         public void onScrollStateChanged(AbsListView view, int scrollState) {
         }
      });

Upvotes: 1

breakline
breakline

Reputation: 6093

You can use the hide() method like:

ActionBar actionBar = getSupportActionBar();
actionBar.hide();

But its API version dependent, check here:

http://developer.android.com/guide/topics/ui/actionbar.html

Upvotes: 0

Related Questions