title: How to show menu items in Toolbar in Fragment class?
body: <p>I have added a menu in my fragment and would like to display menu items in the toolbar. </p>
  
  <p>the menu xml is as follows:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &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/action_note"
          android:icon="@drawable/ic_more_24dp"
          app:showAsAction="always"
          android:visible="true"
          android:orderInCategory="1"
          android:title="Note"/&gt;
      &lt;item
          android:id="@+id/action_submit"
          android:icon="@drawable/ic_more_24dp"
          app:showAsAction="always"
          android:orderInCategory="2"
          android:title="Submit"/&gt;
  &lt;/menu&gt;
  </code></pre>
  
  <p>The view that holds the container, which holds the fragments is as follows:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;android.support.constraint.ConstraintLayout
      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:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:context=".DashboardActivity"&gt;
  
      &lt;include layout="@layout/toolbar"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"&gt;
      &lt;/include&gt;
  
      &lt;FrameLayout
          android:id="@+id/container"
          android:layout_width="match_parent"
          android:layout_above="@+id/navigationView"
          android:layout_height="match_parent"
          android:layout_marginBottom="56dp"
          android:layout_marginTop="56dp"
  
         /&gt;
  
      &lt;android.support.design.widget.BottomNavigationView
          android:id="@+id/navigationView"
          android:layout_width="0dp"
          android:layout_height="wrap_content"
          android:layout_marginEnd="0dp"
          android:layout_marginStart="0dp"
          android:background="?android:attr/windowBackground"
          app:layout_constraintBottom_toBottomOf="parent"
          app:layout_constraintLeft_toLeftOf="parent"
          app:layout_constraintRight_toRightOf="parent"
          app:itemBackground="@android:color/white"
          app:itemIconTint="@color/cardview_dark_background"
          app:itemTextColor="@android:color/black"
          app:menu="@menu/navigation_menu"
          /&gt;
  
  &lt;/android.support.constraint.ConstraintLayout&gt;
  </code></pre>
  
  <p>The code to display the menu in the fragment is as follows:</p>
  
  <pre><code>@Override
  public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
  
      super.onViewCreated(view, savedInstanceState);
      setHasOptionsMenu(true);
      init();
  }
  </code></pre>
  
  <p>Then the code for the menu</p>
  
  <pre><code>@Override
  public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
      super.onCreateOptionsMenu(menu, inflater);
      inflater.inflate(R.menu.menu_attendance, menu);
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      // Handle item selection
      switch (item.getItemId()) {
          case R.id.action_submit:
  
              return true;
          case R.id.action_note:
  
              return true;
          default:
              return super.onOptionsItemSelected(item);
      }
  }
  </code></pre>
  
  <p>I have added the hasOptionMenu (true) and still the menu items will not display in the toolbar </p>