Home > other >  Is there any solution to hide a menu item in bottomNavigationView without removing the space given t
Is there any solution to hide a menu item in bottomNavigationView without removing the space given t

Time:12-19

I'am trying to hide a menu item, and keeping the other menu items in their positions.

Here is my menu: menu before removing any item

I mean when I use this code

navigation.getMenu().removeItem(R.id.composeur); 

the item is removed but other items change their positions: see here the items moved

and when I use

navigation.findViewById(R.id.composeur).setVisibility(View.INVISIBLE);

the item composeur is invisible, but when I click on another item for example "sms" it shows again. when using view.INVISIBLE

I tried to use view.GONE, but same issue, the items change their positions! I'am looking for a solution to how to remove an item from menu and keeping its space and not showing again when clicking on other items!

here is my class of navigationViewHelper

static class BottomNavigationViewHelper {

        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);
                    item.setShifting(false);
                    // set once again checked value, so view will be updated
                    item.setChecked(item.getItemData().isChecked());
                }
            } catch (NoSuchFieldException e) {
                Log.e("ERROR NO SUCH FIELD", "Unable to get shift mode field");
            } catch (IllegalAccessException e) {
                Log.e("ERROR ILLEGAL ALG", "Unable to change value of shift mode");
            }
        }
    }

there is no click listener for the bottom navigation view

CodePudding user response:

Try this code..

    navigation.getMenu().findItem(R.id.composeur).setIcon(0);
    navigation.getMenu().findItem(R.id.composeur).setTitle(null);
    navigation.getMenu().findItem(R.id.composeur).setCheckable(false);

These lines will consume space and nothing will be shown on UI as per your requirement.

  • Related