1

I looked into stackoverflow, and found a solution on how to remove animation from the default bottom navigation.

Now i need to remove the title from bottom navigation. I set empty string in title of bottom navigation xml file, but it does not change the position of images. I'm working with v27

I need to center the images in bottom navigation. once text is removed.

This is my code.

 //OnCreate 

        BottomNavigationViewHelper.removeShiftMode(bottomNavigationView);

Static Class inside MainActivity

public static class BottomNavigationViewHelper {
    @SuppressLint("RestrictedApi")
    public 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);
                //noinspection RestrictedApi
                item.setShiftingMode(false);
                // set once again checked value, so view will be updated
                //noinspection RestrictedApi
                item.setChecked(item.getItemData().isChecked());
            }
        } catch (NoSuchFieldException e) {
            Log.e("BottomNav", "Unable to get shift mode field", e);
        } catch (IllegalAccessException e) {
            Log.e("BottomNav", "Unable to change value of shift mode", e);
        }
    }
}
forpas
  • 160,666
  • 10
  • 38
  • 76
dev90
  • 7,187
  • 15
  • 80
  • 153

3 Answers3

7

You could try to add the app:labelVisibilityMode to "unlabeled"

 <android.support.design.widget.BottomNavigationView
        android:id="@+id/navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:labelVisibilityMode="unlabeled"/>
tijn167
  • 547
  • 2
  • 21
1

I use variations of the below code to customize the labels of BottomNavigationView which are essentially TextViews:

private void removeBottomNavigationLabels(BottomNavigationView bottomNavigationView) {
    for (int i = 0; i < bottomNavigationView.getChildCount(); i++) {
        View item = bottomNavigationView.getChildAt(i);

        if (item instanceof BottomNavigationMenuView) {
            BottomNavigationMenuView menu = (BottomNavigationMenuView) item;

            for (int j = 0; j < menu.getChildCount(); j++) {
                View menuItem = menu.getChildAt(j);

                View small = menuItem.findViewById(android.support.design.R.id.smallLabel);
                if (small instanceof TextView) {
                    ((TextView) small).setVisibility(View.GONE);
                }
                View large = menuItem.findViewById(android.support.design.R.id.largeLabel);
                if (large instanceof TextView) {
                    ((TextView) large).setVisibility(View.GONE);
                }
            }
        }
    }

    BottomNavigationMenuView menuView = (BottomNavigationMenuView) bottomNavigationView.getChildAt(0);
    for (int i = 0; i < menuView.getChildCount(); i++) {
        final View iconView = menuView.getChildAt(i).findViewById(android.support.design.R.id.icon);
        iconView.setPadding(0, 40, 0, 0);
        ViewGroup.LayoutParams layoutParams = iconView.getLayoutParams();
        DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
        layoutParams.height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 32, displayMetrics);
        layoutParams.width = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 32, displayMetrics);
        iconView.setLayoutParams(layoutParams);
    }
}

You can call it like this:

removeBottomNavigationLabels(yourBottomNavigationView); 

You could also try similarly to change the visibility, padding or height of the TextViews.

forpas
  • 160,666
  • 10
  • 38
  • 76
  • Thanks @forpas, this removes the text, but the images are still not centralized, I need to know a way to centralized images in bottom navigation after removing text – dev90 Dec 18 '18 at 10:53
  • 1
    @Kirmani88 I believe you mean vertically. Did you also try to set the height of the labels to 0? – forpas Dec 18 '18 at 10:55
  • Yes i want it to center it vertically, can you please tell me how to set labels height to 0? – dev90 Dec 18 '18 at 11:09
  • still its not vertically aligned :( – dev90 Dec 18 '18 at 11:58
  • Check my edited answer. You can change the numbers for padding (40) and size (32) as you wish. – forpas Dec 18 '18 at 12:33
-2

try using these attributes:

showUnselectedLabels: false
showSelectedLabels: false
sud007
  • 5,824
  • 4
  • 56
  • 63