title: Android: Open menu programmatically
body: <p>I've been trying to add a functionality to my android application such that when I click a button, menu listing should be visible:</p>
  <p>Here is my code:</p>
  <p>menu.xml:</p>
  <pre><code>&lt;menu xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
        xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
        xmlns:tools=&quot;http://schemas.android.com/tools&quot;
        tools:context=&quot;com.example.MainActivity&quot; &gt;
  
      &lt;item android:id=&quot;@+id/action_onthego_sentence&quot;
            android:title=&quot;settings&quot;
            android:orderInCategory=&quot;100&quot;
            app:showAsAction=&quot;never&quot; /&gt;
  
  &lt;/menu&gt;
  </code></pre>
  <p>From the main activity, upon clicking a button, I do:</p>
  <pre><code>        button.setOnClickListener( new View.OnClickListener()
          {
              @Override
              public void onClick( View view )
              {
                  runOnUiThread( new Runnable()
                  {
                      @Override
                      public void run()
                      {
                          openOptionsMenu();
                      }
                  } );
              }
          } );
  </code></pre>
  <p>What I need is:</p>
  <p><a href="https://i.stack.imgur.com/ZnTMn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZnTMn.png" alt="enter image description here" /></a></p>
  <p>As shown in the image, I'd like to see the menu is opened. Any suggestions please?</p>