Flugrek
Flugrek

Reputation: 153

Buttons on Bottom navigation bar are not on their position

I'm trying to create a bottom navigation bar but the buttons are moving to the right

enter image description here

how can fix the view in the bottom navigation bar to look like this?

enter image description here

Upvotes: 1

Views: 1039

Answers (1)

Uthaya
Uthaya

Reputation: 373

If you need like that one, You need set ShiftMode following like :

public static void disableShiftMode(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);

    } catch (NoSuchFieldException e) {
        Log.e("BNVHelper", "Unable to get shift mode field", e);
    } catch (IllegalAccessException e) {
        Log.e("BNVHelper", "Unable to change value of shift mode", e);
    }
}

And send your Buttom NavigationView :

        BottomNavigationView bottomNavigationView = (BottomNavigationView) findViewById(R.id.navigation);
        disableShiftMode(bottomNavigationView);

That's all Thank you.

Upvotes: 2

Related Questions