I am using a Toolbar inside a ListFragment in Android and can hide/show it during scrolling. I implement AbsListView.OnScrollListener
and use this code inside:
@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
// Leave this empty
}
/**
* Method to detect if the scroll status changed
*
* @param listView
* @param scrollState
*/
@Override
public void onScrollStateChanged(AbsListView listView, int scrollState) {
if (!isTablet) {
final int currentFirstVisibleItem = listView.getFirstVisiblePosition();
if (currentFirstVisibleItem > mLastFirstVisibleItem) {
((ActionBarActivity) getActivity()).getSupportActionBar().hide();
} else if (currentFirstVisibleItem < mLastFirstVisibleItem) {
((ActionBarActivity) getActivity()).getSupportActionBar().show();
}
mLastFirstVisibleItem = currentFirstVisibleItem;
}
}
This way the Toolbar is hidden when I scroll down and shown if I scroll upwards. But the animation is very "hard" and I would like to have a smoother transition. It should look like this (without tabs, just the Toolbar): https://cms-images.idgesg.net/images/article/2014/10/playscroll-100509755-large.gif