Android Studio - How can I make an item invisible in the Navigation Drawer menu?

0

I am using the resources of MaterialDrawer - Mikepenz

But I can not find an attribute that allows me to make invisible certain items of the NavigationDrawer.

MainActivity.java

private void createNavigationDrawer(Bundle savedInstanceState){
    //Handle Toolbar
    setSupportActionBar(toolbar);

    //Create Header Drawer
    accountHeader = new AccountHeaderBuilder()
            .withActivity(this)
            .withTranslucentStatusBar(true)
            //.withHeaderBackground(R.drawable.header)
            .withSavedInstance(savedInstanceState)
            .build();

    //Create Drawer Layout
    drawer = new DrawerBuilder()
            .withActivity(this)
            .withToolbar(toolbar)
            .withHasStableIds(true)
            .withItemAnimator(new AlphaCrossFadeAnimator())
            .withAccountHeader(accountHeader)
            .addDrawerItems(
                    new PrimaryDrawerItem().withName("Item 1").withIdentifier(1).withSelectable(true).withEnabled(true),

                    new SectionDrawerItem().withName("Group Item").withEnabled(true),
                    new ExpandableBadgeDrawerItem().withName("Item 2").withIdentifier(2).withSelectable(true).withEnabled(true).withSubItems(
                            new SecondaryDrawerItem().withName("Item 2.1").withIdentifier(21).withSelectable(true).withLevel(2),
                            new SecondaryDrawerItem().withName("Item 2.2").withIdentifier(21).withSelectable(true).withLevel(2)
                    )
.withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
                @Override
                public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
                    /*switch ((int) drawerItem.getIdentifier()){
                        case 1:
                            break;
                        case 2:
                            break;
                        case 3:
                            break;
                        case 4:
                            break;
                        case 5:
                            break;
                        case 6:
                            break;
                    }*/
                    return false;
                }
            })
            .withSavedInstance(savedInstanceState)
            .withShowDrawerOnFirstLaunch(false)
            .withShowDrawerUntilDraggedOpened(false)
            .build();
}
    
asked by Leonidas 16.10.2018 в 22:35
source

1 answer

0

Hello that library has the method removeItem if you have saved the Drawer you should only do this:

mDrawer.removeItem(i);

Pass as the parameter the identifier of the item you want to remove. You can also add it again if you need it with addItem

    
answered by 17.10.2018 / 23:26
source