aurelhubert / ahbottomnavigation

A library to reproduce the behavior of the Bottom Navigation guidelines from Material Design.
3.84k stars 684 forks source link

Removing shifting mode of item selected #292

Open ahmedmoussa8 opened 7 years ago

ahmedmoussa8 commented 7 years ago

Great work, How could I remove shifting mode of the item selected? Thanks.

ahmedmoussa8 commented 7 years ago

after some searches on this problem, I've found a solution but for BottomNavigationView . Can we use it here?

static void removeShiftMode(BottomNavigationView view) {
    BottomNavigationMenuView menuView = (BottomNavigationMenuView) view.getChildAt(0);
    try {
        Field shiftingMode = menuView.getClass().getDeclaredField("mShiftingMode");
        shiftingMode.setAccessible(true);
        shiftingMode.setBoolean(menuView, false);
        shiftingMode.setAccessible(false);
        for (int i = 0; i < menuView.getChildCount(); i++) {
            BottomNavigationItemView item = (BottomNavigationItemView) menuView.getChildAt(i);
            item.setShiftingMode(false);
            // set once again checked value, so view will be updated
            item.setChecked(item.getItemData().isChecked());
        }
    } catch (NoSuchFieldException e) {
        Log.e("ERROR NO SUCH FIELD", "Unable to get shift mode field");
    } catch (IllegalAccessException e) {
        Log.e("ERROR ILLEGAL ALG", "Unable to change value of shift mode");
    }
}
ssawchenko commented 7 years ago

I also have clients that are asking to have the "shifting" mode disabled. Putting in my +1 to have this supported in the library <3

ahmedmoussa8 commented 7 years ago

You can use this library instead: https://github.com/ittianyu/BottomNavigationViewEx I have used it and it's working as charming.

beast-shubham commented 6 years ago

+1 for a request to add this feature!

beast-shubham commented 6 years ago

@ssawchenko I kinda found a hack. Suppose you have 5 icons in the navbar, try using

bottomNavigation.setTitleState(AHBottomNavigation.TitleState.ALWAYS_SHOW);

This removes the shifting animation.

anoreg commented 6 years ago
 freplace this value in app's manifest: 
<dimen name="bottom_navigation_margin_top_inactive" tools:override="true">6dp</dimen>
<dimen name="bottom_navigation_text_size_active" tools:override="true">12sp</dimen>

You can find the original value is:
<dimen name="bottom_navigation_margin_top_active">6dp</dimen>
<dimen name="bottom_navigation_margin_top_inactive">8dp</dimen>
<dimen name="bottom_navigation_text_size_active">14sp</dimen>
<dimen name="bottom_navigation_text_size_inactive">12sp</dimen>

So, just override these values with yours :)

also you can setTitleSize(activesize, inactivesize)

Pirksy commented 5 years ago

override dimens with <dimen name="bottom_navigation_small_selected_width_difference">0.1dp</dimen>

steam0111 commented 5 years ago

@ssawchenko I kinda found a hack. Suppose you have 5 icons in the navbar, try using

bottomNavigation.setTitleState(AHBottomNavigation.TitleState.ALWAYS_SHOW);

This removes the shifting animation.

it works for me