-1

I have tried implementing the new NavigationView from the Android Support Design library. The app consists of a a DrawerLayout with Fragment holding a NavigationView. A simple menu with icons.

  1. I'm starting the app with no items checked.

  2. I then click on an item the item gets checked, and both text and icon shows checked state:

  3. I then open and close the drawer by swiping. What happens now is that the text for my selected item shows selected state, but the icon does not. On the other hand the item above has the icon showing checked state.

Is this a bug or have I done something wrong?

I project with app screenshots can be viewed here:

https://bitbucket.org/adirdal/navigationviewtest

Aslak
  • 109
  • 8

2 Answers2

0

Solution is to put the NavigationView directly into the DrawerLayout, not inside a Fragment.

Aslak
  • 109
  • 8
  • I have tried putting the navigation view inside relative layout which is under drawer layout but still facing the same issue... – Ravi Yadav Jul 01 '15 at 13:36
0

Facing the same issue like you...(I have removed the navigation view from fragment). This solution is working for me. You can try without removing navigation view from fragment.

Try this structure :

public your class
{
private int mNavItemId;
private static final String NAV_ITEM_ID = "navItemId";
onCreate()
{
      if (null == savedInstanceState) {
            mNavItemId = R.id.home;
        } else {
            mNavItemId = savedInstanceState.getInt(NAV_ITEM_ID);
        }

        //call setupnavigationview
        setupnavigationview();
}

private void setupNavigationView() {

        mNavigationView = (NavigationView) findViewById(R.id.navigation_view);
        mNavigationView.getMenu().findItem(mNavItemId).setChecked(true);
        mNavigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(MenuItem menuItem) {
                // update highlighted item in the navigation menu
                menuItem.setChecked(true);
                mNavItemId = menuItem.getItemId();
                mDrawerLayout.closeDrawer(GravityCompat.START);

                    switch (menuItem.getItemId()) {
                    case R.id.id_of_your_menu_item:
                        call your fragment
                        break;

                });

                }

                @Override
    protected void onSaveInstanceState(final Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.putInt(NAV_ITEM_ID, mNavItemId);
    }
    @Override
    public boolean onOptionsItemSelected(final MenuItem item) {
        if (item.getItemId() == android.support.v7.appcompat.R.id.home) {
            return mDrawerToggle.onOptionsItemSelected(item);
        }
        return super.onOptionsItemSelected(item);
    }
}           
Ravi Yadav
  • 2,296
  • 3
  • 25
  • 32