title: How can i add spinner to the toolbar in the particular fragment.Can anyone tell me how can i do this?
body: <p>This is my <code>onActivityCreated()</code> method:  </p>
  
  <pre><code>    @Override
      public void onActivityCreated(@Nullable Bundle savedInstanceState) {       
          setHasOptionsMenu(true);
          super.onActivityCreated(savedInstanceState);
      }
  </code></pre>
  
  <p>This is my <code>onCreateOptionsMenu()</code> method when i inflate the spinner and set the adapter:  </p>
  
  <pre><code>    @Override
      public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
          inflater.inflate(R.menu.menu, menu);
          MenuItem menuItem = menu.findItem(R.id.menu_spinner);
          mCountrySpinner = (Spinner) MenuItemCompat.getActionView(menuItem);
  
          ArrayAdapter&lt;String&gt; countryAdapter = new ArrayAdapter&lt;String&gt;(getContext(), android.R.layout.simple_spinner_dropdown_item, mCountryList);
                  countryAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
          mCountrySpinner.setAdapter(countryAdapter);
          super.onCreateOptionsMenu(menu, inflater);
       }
  </code></pre>
  
  <p>This is my menu xml where i added the item and set <code>app:actionViewClass</code> as <code>android.widget.Spinner</code>:</p>
  
  <pre><code>&lt;menu 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"
      tools:context=".activity.MainActivity"&gt;
  </code></pre>
  
  <p>This is the item i inflated in the menu xml:</p>
  
  <pre><code>&lt;item
      android:id="@+id/menu_spinner"
      android:background="#ff00"
      android:title="@string/countryname"
      app:actionViewClass="android.widget.Spinner"
      app:showAsAction="always"&gt;&lt;/item&gt;
  &lt;/menu&gt;
  </code></pre>