title: Android ActionBar hide/show when scrolling list view
body: <p>I want to hide/show the compatibility action bar as the user scrolls up/down a listview. When the action bar disappears the list will occupy also the action bar's space.</p>
  
  <p>I've followed an approach but it generates an ugly flickering. Does anyone have a proper solution for this problem? The desired behaviour is like the hide/show mechanism in the Google+ app (I'm not interested about the footer).</p>
  
  <p>What I've tried is presented below:</p>
  
  <pre><code>boolean tabletSize = getResources().getBoolean(R.bool.isTablet);
      if (!tabletSize) {
          final ActionBar actionBar = ((ActionBarActivity) getActivity()).getSupportActionBar();
          lvNews.setOnScrollListener(new AbsListView.OnScrollListener() {
              private int mLastFirstVisibleItem;
  
              @Override
              public void onScrollStateChanged(AbsListView view, int scrollState) {
              }
  
              @Override
              public void onScroll(AbsListView view, int firstVisibleItem,
                                   int visibleItemCount, int totalItemCount) {
  
                  if (mLastFirstVisibleItem &lt; firstVisibleItem) {
                      if (actionBar.isShowing()) {
                          actionBar.hide();
                      }
                  }
  
                  if (mLastFirstVisibleItem &gt; firstVisibleItem) {
                      if (!actionBar.isShowing()) {
                          actionBar.show();
                      }
                  }
                  mLastFirstVisibleItem = firstVisibleItem;
              }
          });
      }
  </code></pre>