title: Dynamically added menu items disappear on click in Navigation Drawer
body: <p>I followed the <a href="https://developer.android.com/training/implementing-navigation/nav-drawer" rel="nofollow noreferrer">Android Developer documentation</a> to create a navigation drawer.</p>
  
  <p>Then I wanted to add 2 groups of menu items. One for user created lists, the other for labels. Since I couldn't directly set titles to groups, I followed the tutorial <a href="https://stackoverflow.com/a/36542903/4673960">HERE</a> and wrapped groups in  tags.</p>
  
  <p>My XML menu looks like this: <img src="https://i.imgur.com/bhT7DpA.png" alt="XML Menu"></p>
  
  <p>In onCreate I find the NavigationView using its id, then get its menu, get the first  by its id, get the item's SubMenu and add MenuItems:</p>
  
  <pre><code>NavigationView navigationView = findViewById(R.id.nav_view);
  Menu menu =  navigationView.getMenu();
  MenuItem item = menu.findItem(R.id.item_lists);
  SubMenu sbLists = item.getSubMenu();
  sbLists.add(0, 0, 0, "Android").setIcon(R.drawable.ic_android);
  sbLists.add(0, 1, 0, "iOS").setIcon(R.drawable.ic_ios);
  </code></pre>
  
  <p>And:</p>
  
  <pre><code>navigationView.setNavigationItemSelectedListener(
      menuItem -&gt; {
          // set item as selected to persist highlight
          menuItem.setChecked(true);
          // close drawer when item is tapped
          mDrawerLayout.closeDrawers();
  </code></pre>
  
  <p>When I click the items added in XML, the drawer closes and if I open it again I can see the item is selected. 
  However, with the items added in onCreate, this is what I see after I re-open the drawer:</p>
  
  <p>Clicking this one
  <img src="https://i.imgur.com/au26OFE.png" alt="Before click"></p>
  
  <p>It's gone
  <img src="https://i.imgur.com/5hl6toX.png" alt="After"></p>
  
  <p>I've tried searching on Stack Overflow and found only one question with the same problem <a href="https://stackoverflow.com/questions/38989663/navigation-items-title-disappeared-when-clicked">Navigation item&#39;s title disappeared when clicked</a> , however, the solution is to set the item text color to black. That doesn't fix the item not being selected problem and  doesn't fix the icon disappearing either.</p>
  
  <p>Please let me know what I'm doing incorrectly, thank you!</p>
  
  <p>Edit:
  Here's what my Theme looks like in styles.xml:</p>
  
  <pre><code>&lt;style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"&gt;
      &lt;item name="windowActionModeOverlay"&gt;true&lt;/item&gt;
      &lt;item name="colorAccent"&gt;@color/colorAccent&lt;/item&gt;
  
      &lt;item name="iconColor"&gt;@color/icons_light&lt;/item&gt;
      &lt;item name="toolbarIconColor"&gt;@color/icons_light&lt;/item&gt;
      &lt;item name="android:textColorPrimary"&gt;@color/primary_text&lt;/item&gt;
  &lt;/style&gt;
  </code></pre>