Bottombar: Hide/Show the BottomBar

Created on 10 Oct 2016  路  11Comments  路  Source: roughike/BottomBar

I think you should provide a way to hide and show the ButtonBar programatically (with the animation).

Most helpful comment

If your bottombar is in a CoordinatorLayout, you can use behavior to implement hide/show feature, the same way it can be done with a Toolbar :

public void showBottomBar(boolean show){
    CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) mBottomBar.getLayoutParams();
    CoordinatorLayout.Behavior behavior2 = params.getBehavior();
    if (behavior2 != null) {
        behavior2.onNestedFling(mCoordinatorLayout, mBottomBar, null, 0, show ? -10000: 10000, true);
    }
}

All 11 comments

how can we show or hide bottom bar programmatically, i need to show bottombar fixed for the screens which does not have scroll, how can i do that

If your bottombar is in a CoordinatorLayout, you can use behavior to implement hide/show feature, the same way it can be done with a Toolbar :

public void showBottomBar(boolean show){
    CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) mBottomBar.getLayoutParams();
    CoordinatorLayout.Behavior behavior2 = params.getBehavior();
    if (behavior2 != null) {
        behavior2.onNestedFling(mCoordinatorLayout, mBottomBar, null, 0, show ? -10000: 10000, true);
    }
}

Yeah I have implemented it, but a way to do it within the lib would be better :smile:

It looks like it's slightly implemented in the bottom Bar already but the method is private and does the reverse of what it says. Here's what's in the class.

/** * Toggle translation of BottomBar to hidden and visible in a CoordinatorLayout. * * @param visible true resets translation to 0, false translates view to hidden */ private void toggleShyVisibility(boolean visible) { BottomNavigationBehavior<BottomBar> from = BottomNavigationBehavior.from(this); if (from != null) { from.setHidden(this, visible); } }

The BottomNavigationBehavior setHidden method is package level. So I extended the BottomBar class using the same package to be able to call this method.

`
package com.roughike.bottombar;

import android.content.Context;
import android.util.AttributeSet;
public class CSBottomBar extends BottomBar {

public CSBottomBar(Context context) {
    super(context);
}

public CSBottomBar(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public void toggleShyVisibility( boolean visible ) {
    BottomNavigationBehavior<CSBottomBar> from = BottomNavigationBehavior.from(this);
    if (from != null) {
        from.setHidden(this, visible);
    }
}

}`

I kept the method "as is" even though it does the reverse of what the documentation states. Passing false makes it visible. True makes it disappear. And it is animated.

Great hack! However it doesn't work for me:

Fatal Exception: java.lang.IllegalArgumentException: The view is not associated with BottomNavigationBehavior
       at com.roughike.bottombar.BottomNavigationBehavior.from(BottomNavigationBehavior.java:122)
       at com.roughike.bottombar.CSBottomBar.toggleShyVisibility(CSBottomBar.java:20)

My bottom bar is declared non-shy, perhaps that's why. I'd like a non-shy bottom bar and only hide the bottom bar in certain situations, like when the keyboard is displayed, which could greatly confuse the user.

Yeah sorry, guess I should of said this is for the Shy Bottom bar. I had some situations where the user would filter results when the bar was still hidden and there was no way to get it to show back up. This solved my problem by letting me tell the bottom bar to show itself if the results of the filter were empty.

I have the same problem - I do programmatical transition between tabs and I would like the bar to reappear on trasition if it was hidden

mBottomBar.animate().translationY(0)

@mStepkowski Great! thanks a lot.

+1

With the versions 2.3.0 and up, in shy mode, you can show / hide the bar as follows:

// Show:
bottomBar.getShySettings().showBar();

// Hide:
bottomBar.getShySettings().hideBar();

On non-shy mode, it's up to you how to hide / show it, since the BottomBar is just a regular View.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ryanhoo picture ryanhoo  路  3Comments

yerenutku picture yerenutku  路  4Comments

lamba92 picture lamba92  路  5Comments

Hiike picture Hiike  路  4Comments

avivcaspi picture avivcaspi  路  8Comments