BottomNavigationView with more than 3 Items: tab title is hiding

后端 未结 10 901
-上瘾入骨i
-上瘾入骨i 2020-12-07 16:01

I\'m using BottomNavigationView with using Android Support Desing Library 25. But when I switch the tabs, the other tab\'s title is hiding. But there is no hiding issue actu

10条回答
  •  半阙折子戏
    2020-12-07 16:44

    This works for me in API 26 :

     navigation = (BottomNavigationView) view.findViewById(R.id.bottom_navigation);
    
    
         try{disableShiftMode(navigation);}catch(Exception ew){}
    

    Make this method in your Activity or Fragment where you want to call:

     @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);
                item.setShiftingMode(false);
    
                item.setChecked(item.getItemData().isChecked());
            }
        } catch (NoSuchFieldException e) {
    
        } catch (IllegalAccessException e) {
    
        }
    }
    

提交回复
热议问题