title: How to create a custom PopupMenu in Android
body: <p>How can I replicate something like I made below in Balsamiq? </p>
  
  <p>I made this menu, but it is only displaying the text of the items (not the icons). Is it possible to display both the title and icon in a PopupMenu?</p>
  
  <p>Here is my <code>create_post_menu.xml</code></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  
  &lt;menu xmlns:android="http://schemas.android.com/apk/res/android" &gt;
  
      &lt;item
          android:id="@+id/action_photo"
          android:icon="@drawable/ic_action_camera"
          android:title="@string/action_photo"
          android:showAsAction="always|withText" /&gt;
  
      &lt;item
          android:id="@+id/action_video"
          android:icon="@drawable/ic_action_video"
          android:title="@string/action_video"
          android:showAsAction="always|withText" /&gt;
  
      &lt;item
          android:id="@+id/action_text"
          android:icon="@drawable/ic_action_edit"
          android:title="@string/action_text"
          android:showAsAction="always|withText" /&gt;
  
      &lt;item
          android:id="@+id/action_link"
          android:icon="@drawable/ic_action_web_site"
          android:title="@string/action_link"
          android:showAsAction="always|withText" /&gt;
  
  &lt;/menu&gt;
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/30dVu.png" alt="A"></p>
  
  <p><strong>Edit</strong></p>
  
  <p>Here are my <code>onCreateOptionsMenu</code> and <code>onOptionsItemSelected</code> methods:</p>
  
  <pre><code>@Override
  public boolean onCreateOptionsMenu(Menu menu) {
      MenuInflater inflater = getMenuInflater();
      inflater.inflate(R.menu.main, menu);
      return super.onCreateOptionsMenu(menu);
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      if (item.getItemId() == R.id.action_new) {
          View menuItemView = findViewById(R.id.action_new);
          PopupMenu popupMenu = new PopupMenu(this, menuItemView);
          popupMenu.inflate(R.menu.create_post_menu);
          popupMenu.show();
          return true;
      } else if(item.getItemId() == R.id.action_search) {
          return true;
      } else if(item.getItemId() == R.id.action_settings) {
          startActivity(new Intent(MainActivity.this, SettingsActivity.class));
          return true;
      } else if(item.getItemId() == R.id.action_help) {
          return true;
      } else {
          return super.onOptionsItemSelected(item);
      }
  }
  </code></pre>