title: Toolbar menu not appearing using navigation drawer and fragment
body: <p>I'm using navigation drawer and toolbar. When I tried to create an option menu on the toolbar of the DrawerActivity, it was not shown. I went through a lot of online resources but still couldn't find a solution. Does anyone know why?</p>
  
  <p><strong>menu_advance.xml</strong>:</p>
  
  <pre><code>&lt;menu xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"&gt;
  
      &lt;item
          android:id="@+id/menu_edit_marker"
          android:orderInCategory="101"
          android:title="@string/menu_edit_marker"
          app:showAsAction="never"/&gt;
  
      &lt;item
          android:id="@+id/menu_config_mode"
          android:orderInCategory="103"
          android:title="@string/reconfig_mode_on"
          app:showAsAction="never"/&gt;
  
      &lt;item
          android:id="@+id/menu_installation_mode"
          android:orderInCategory="104"
          android:title="@string/installation_mode_on"
          app:showAsAction="never"/&gt;
  
  &lt;/menu&gt;
  </code></pre>
  
  <p><strong>activity_drawer.xml</strong>:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      xmlns:tools="http://schemas.android.com/tools"
      android:id="@+id/drawer_layout"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:openDrawer="start"&gt;
  
      &lt;LinearLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:orientation="vertical"&gt;
  
          &lt;android.support.v7.widget.Toolbar
              android:id="@+id/drawer_activity_layout"
              android:layout_width="match_parent"
              android:layout_height="?attr/actionBarSize"
              android:background="@color/colorPrimary"
              android:elevation="4dp"
              android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
              app:layout_constraintStart_toStartOf="parent"
              app:layout_constraintTop_toTopOf="parent"
              app:navigationIcon="@drawable/ic_menu_white_24dp"
              app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/&gt;
  
          &lt;android.support.design.widget.CoordinatorLayout
              android:id="@+id/fragment_container"
              android:layout_width="match_parent"
              android:layout_height="match_parent"&gt;
  
          &lt;/android.support.design.widget.CoordinatorLayout&gt;
  
      &lt;/LinearLayout&gt;
  
      &lt;android.support.design.widget.NavigationView
          android:id="@+id/nav_view"
          android:layout_width="wrap_content"
          android:layout_height="match_parent"
          android:layout_gravity="start"
          app:headerLayout="@layout/drawer_header"
          app:menu="@menu/menu_drawer" /&gt;
  
  &lt;/android.support.v4.widget.DrawerLayout&gt;
  </code></pre>
  
  <p><strong>DrawerActivity.java</strong>:</p>
  
  <pre><code>    public class DrawerActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
  
      private DrawerLayout drawer_layout;
  
      @Override
      protected void onCreate(@Nullable Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_drawer);
  
          Toolbar toolbar = findViewById(R.id.drawer_activity_toolbar);
          setSupportActionBar(toolbar);
  
          drawer_layout = findViewById(R.id.drawer_layout);
          NavigationView navigation_view = findViewById(R.id.nav_view);
          navigation_view.setNavigationItemSelectedListener(this);
  
          ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer_layout, toolbar,
                  R.string.navigation_drawer_open, R.string.navigation_drawer_close);
          drawer_layout.addDrawerListener(toggle);
          toggle.setDrawerIndicatorEnabled(true);
          toggle.syncState();
  
          if (savedInstanceState == null) {
              getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new MapFragment(), "MAP FRAGMENT").commit();
              navigation_view.setCheckedItem(R.id.office_map);
          }
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          getMenuInflater().inflate(R.menu.menu_advance, menu);
          return true;
      }
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          switch (item.getItemId()) {
              case R.id.menu_config_mode:
                  Toast.makeText(this, "config", Toast.LENGTH_SHORT).show();
                  return true;
              ....
          }
          return super.onOptionsItemSelected(item);
      }
  </code></pre>
  
  <p><strong>MapFragment.java</strong>:</p>
  
  <pre><code>    @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
          View view = inflater.inflate(R.layout.fragment_map, container, false);
  
          setHasOptionsMenu(true);
          toolbar = view.findViewById(R.id.drawer_activity_toolbar);
          ((AppCompatActivity) requireActivity()).setSupportActionBar(toolbar);
  
      ....
      }
  
      @Override
      public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
          menu.clear();
          inflater.inflate(R.menu.menu_advance, menu);
          optionMenu = menu;
          super.onCreateOptionsMenu(menu, inflater);
      }
  
  </code></pre>
  
  <p><strong>Manifest</strong>:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:dist="http://schemas.android.com/apk/distribution"
      package="com.example.vlcips"&gt;
  
      &lt;uses-permission android:name="android.permission.INTERNET"/&gt;
      &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
  
      &lt;uses-feature android:name="android.hardware.camera"
          android:required="false" /&gt;
  
      &lt;application
          android:allowBackup="true"
          android:icon="@mipmap/ic_launcher"
          android:label="@string/app_name"
          android:roundIcon="@mipmap/ic_launcher_round"
          android:supportsRtl="true"
          android:theme="@style/AppTheme"&gt;
          &lt;activity
              android:name=".DrawerActivity"
              android:hardwareAccelerated="true"
              android:screenOrientation="portrait"
              android:theme="@style/AppTheme.NoActionBar"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
      &lt;/application&gt;
  
      &lt;dist:module dist:instant="true" /&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p><strong>SOLUTION:</strong></p>
  
  <p>Bug found! Do not do setSupportActionBar(toolbar) again in the fragment. You just need to set it once in the activity.</p>