4

I'm trying to have ALL icons centered, I already disabled the shifting mode by using the following code:

/**
 * This is done to remove the shift animation introduced by Android on the bottom navigation view
 * https://stackoverflow.com/a/41690461/4243027
 */
@SuppressLint("RestrictedApi")
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);
        for (int i = 0; i < menuView.getChildCount(); i++) {
            BottomNavigationItemView item = (BottomNavigationItemView) menuView.getChildAt(i);
            //noinspection RestrictedApi
            item.setShiftingMode(false);
            item.setPadding(0,15,0,0);
            // set once again checked value, so view will be updated
            //noinspection RestrictedApi
            item.setChecked(item.getItemData().isChecked());
        }
    } 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 set the title to ""

android:title=""

I have also tried to do the following https://stackoverflow.com/a/40234361/4243027 but it's not working either.

My bottom navigation view looks like this:

Bottom navigation bar

I'm using implementation "com.android.support:design:27.0.1"

EDIT:

As you can see in Layout Inspector, the icon sizes are the same, 63x63 px but the Y of the checked icon is 5 px less.

Layout Inspector

8
  • Are these not centered? Selected icon base looks a bit higher than the others, but I believe it is due to its different size. Commented Jul 31, 2018 at 10:54
  • @DeividasStrioga The checked icon moves a bit to the top, it's not much but you can see the effect, all icon sizes are the same in drawables.
    – aleixrr
    Commented Jul 31, 2018 at 10:56
  • Then it is due to its size. Are they svg icons? If so, you can try adjusting their sizes. Commented Jul 31, 2018 at 10:57
  • @DeividasStrioga Yes, they are SVG icons, but all sizes are the same 24x24 dp.
    – aleixrr
    Commented Jul 31, 2018 at 10:59
  • The difference is in paths' sizes then. Try increasing the size of smaller icons. Commented Jul 31, 2018 at 11:00

1 Answer 1

5

As of Design Support Library 28.0.0-alpha1 you can use the property

app:labelVisibilityMode="unlabeled"

Not the answer you're looking for? Browse other questions tagged or ask your own question.