0

I have a navigationView with a headerLayout and also menu attach to it. I didn't used any library for this one. I'm trying to achieved the same effect with google navigationView but the difference is that, not changing account but to view extra's/hidden command (for the admin side if the user is admin).

How do I add/inflate this thing? I have two menu's. I attempt to do this yet, what I get is, it duplicate itself. Causing the navigationView to have the same icons and name's. I created two methods, calling them when the image button is clicked.

Here's my code: MainActivity.java

public void changeNavigationDrawer(){

    mNavigationView = (NavigationView) findViewById(R.id.navigation_view);
    mNavigationView.setItemIconTintList(null);
    mNavigationView.getMenu();
    mNavigationView.inflateMenu(R.menu.navigation_drawer);
    mNavigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            menuItem.setChecked(true);
            mDrawerLayout.closeDrawers();

            int id = menuItem.getItemId();
            switch (id){

                //Nav list no 1 is User Profile
                //Nav list no 2
                case R.id.my_friends:
                    Intent intent_friends = new Intent(MainActivity.this,CommunityFriendsActivity.class);
                    startActivity(intent_friends);
                    finish();
                    break;

                //Nav list no 3
                case R.id.my_feeds:
                    //BY DEFAULT YOU'RE in the FEEDS SECTION
                    break; }
            return true;
        }
    });

}

The other method in the same file:

public void adminNavigationDrawer(){
    mNavigationView = (NavigationView) findViewById(R.id.navigation_view);
    mNavigationView.setItemIconTintList(null);
    mNavigationView.inflateMenu(R.menu.navigation_drawer_admin);
    mNavigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(MenuItem item) {

            int id = item.getItemId();
            switch (id){

            }

            return true;
        }
    });

}

ImageHeader

RoCkDevstack
  • 3,517
  • 7
  • 34
  • 56

1 Answers1

0

Check out this library https://github.com/mikepenz/MaterialDrawer.

The material drawer library is easy, flexible(absolutely NO limits) and you can take advantage predefined classes.

You can set up the Material Drawer in few minutes using this library.

or If you want to do it using by your own. You can create two groups and perform hide/show on each group on clicking arrow button in your header view.

// Edited

for hiding and showing the group

https://stackoverflow.com/a/37202286/5028508

Community
  • 1
  • 1
Shubham AgaRwal
  • 4,355
  • 8
  • 41
  • 62