How to disable BottomNavigationView shift mode?

后端 未结 21 1952
Happy的楠姐
Happy的楠姐 2020-11-22 15:55

BottomNavigationView doesn\'t show menu\'s title that are inactive.

How to show titles of all menu elements in bottomNavigationBar? The problem is that in my case s

相关标签:
21条回答
  • 2020-11-22 16:49

    To disable the text animation and decrease font size use this in your dimens.xml file:

    <dimen name="design_bottom_navigation_text_size">10sp</dimen> 
    <dimen name="design_bottom_navigation_active_text_size">10sp</dimen>
    
    0 讨论(0)
  • 2020-11-22 16:50

    To your BottomNavigationView add app:labelVisibilityMode="unlabeled"

    <android.support.design.widget.BottomNavigationView
            app:menu="@menu/bn_menu"
            android:layout_height="56dp"
            android:layout_width="match_parent"
            app:labelVisibilityMode="unlabeled">
    
    </android.support.design.widget.BottomNavigationView>
    

    which results in the following

    0 讨论(0)
  • 2020-11-22 16:52

    UPDATE

    in Android sdk version 28 and above they have changed item.setShiftingMode(false) to item.setShifting(false)

    Also they removed the field mShiftingMode

    So usage will be

     BottomNavigationHelper.removeShiftMode(bottomNav);
     bottomNav.setLabelVisibilityMode(LabelVisibilityMode.LABEL_VISIBILITY_LABELED);
    
    
     private static final class BottomNavigationHelper {
        @SuppressLint("RestrictedApi")
        static void removeShiftMode(BottomNavigationView view) {
            BottomNavigationMenuView menuView = (BottomNavigationMenuView) view.getChildAt(0);
            for (int i = 0; i < menuView.getChildCount(); i++) {
                BottomNavigationItemView item = (BottomNavigationItemView) menuView.getChildAt(i);
                //noinspection RestrictedApi
                item.setShifting(false);
                item.setLabelVisibilityMode(LabelVisibilityMode.LABEL_VISIBILITY_LABELED);
    
                // set once again checked value, so view will be updated
                //noinspection RestrictedApi
                item.setChecked(item.getItemData().isChecked());
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题