Ok, so hiding the action bar is something doable. But, how can we hide the (newly introduced) toolbar in our activity?
I am making an app with an activity having theme as theme.apcompat.light.noactionbar(to hide the action bar) , I have placed a toolbar with slidingtablayout below it. And below it is my listview.
What I want is to hide the toolbar when I scroll the listview up. But the slidingtablayout should remain there. And while in middle of the listview if I scroll down, the toolbar should again be visible.
Just call stopScroll(myListView); when you need to stop scroll. Show activity on this post. // Stop scrolling smoothScrollBy(0, 0);
Add a app:layout_behavior to a RecyclerView or any other View prepared of nested scrolling such as NestedScrollView. By Adding the above property in your XML, you can achieve the ability to hide and showing toolbar while scrolling.
There are different show/hide behaviours such as the full snap, where, with any scroll movement, the Toolbar either completely scrolls into (or out of) view (as seen in the Google plus app), and the partial snap, where you have to scroll to a threshold for the toolbar to either completely scroll in or out of view.
How To Hide Navbar on Scroll Down Step 1) Add HTML: Create a navigation bar: Example <div id="navbar"> <a href="#home"> Home </a> <a href="#news"> News... Step 2) Add CSS: Style the navigation bar: Example #navbar { background-color: #333; /* Black background color... Step 3) Add JavaScript:
toolbar: – A Toolbar is a generalized form of action bars for use within application layouts. Set this flag to your ToolBar. this app:layout_scrollFlags attribute, performs scroll events in the RecyclerView trigger changes inside views declared within AppBarLayout.
Please see my latest answer here using the Design Support Library
:
Hiding the ActionBar on RecyclerView/ListView onScroll
Please see https://stackoverflow.com/a/26547550/950427 and https://github.com/google/iosched/blob/master/android/src/main/java/com/google/samples/apps/iosched/ui/BaseActivity.java.
mToolbar = (Toolbar) findViewById(R.id.toolbar_actionbar);
setSupportActionBar(mToolbar);
getSupportActionBar().setDisplayShowHomeEnabled(true);
mNavigationDrawerFragment = (NavigationDrawerFragment) getFragmentManager().findFragmentById(R.id.fragment_drawer);
mNavigationDrawerFragment.setup(R.id.fragment_drawer, (DrawerLayout) findViewById(R.id.drawer), mToolbar);
mToolbar.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
if (Build.VERSION.SDK_INT >= 16) {
mToolbar.getViewTreeObserver().removeOnGlobalLayoutListener(this);
} else {
mToolbar.getViewTreeObserver().removeGlobalOnLayoutListener(this);
}
mToolbar.animate().translationY(-mToolbar.getBottom()).setInterpolator(new AccelerateInterpolator()).start();
}
});
From: http://pastebin.com/yeMX3VYP
https://stackoverflow.com/a/17767691/950427
I recently wanted the same functionality and this works perfectly for me:
As the user scrolls upward, the ActionBar will be hidden in order to give the user the entire screen to work work with.
As the user scrolls downward and lets go, the ActionBar will return.
getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
listView.setOnScrollListener(new OnScrollListener() {
int mLastFirstVisibleItem = 0;
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) { }
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
if (view.getId() == listView.getId()) {
final int currentFirstVisibleItem = listView.getFirstVisiblePosition();
if (currentFirstVisibleItem > mLastFirstVisibleItem) {
// getSherlockActivity().getSupportActionBar().hide();
getSupportActionBar().hide();
} else if (currentFirstVisibleItem < mLastFirstVisibleItem) {
// getSherlockActivity().getSupportActionBar().show();
getSupportActionBar().show();
}
mLastFirstVisibleItem = currentFirstVisibleItem;
}
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With