Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy opens popupmenu inside action bar
    primarykey
    data
    text
    <p>I am working on an timetable app, but I have a strange problem, I created a popupmenu that opens upon clicking an action-bar item.</p> <p>The popup works, but it opens <strong>inside the action bar</strong>, I want that it opens in the view below.</p> <p><img src="https://i.stack.imgur.com/J9JN7.jpg" alt="enter image description here"></p> <p>My code..</p> <pre><code> @Override public void onCreateOptionsMenu( Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.lists_choice_mode_mulitplue, menu); } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setHasOptionsMenu(true); } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle item selection switch (item.getItemId()) { case R.id.inverse: showPopupMenu(this.getView()); return true; } return false; } private void showPopupMenu(View v){ final Activity activity = getSupportActivity(); PopupMenu popupMenu = new PopupMenu(activity, v); popupMenu.getMenuInflater().inflate(R.menu.popup, popupMenu.getMenu()); popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { Toast.makeText(activity, item.toString(), Toast.LENGTH_LONG).show(); return true; } }); popupMenu.show(); } </code></pre> <p>My .xml layout files</p> <p>popup.xml</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;group android:id="@+id/group_popupmenu"&gt; &lt;item android:id="@+id/menu1" android:title="Popup menu item 1"/&gt; &lt;item android:id="@+id/menu2" android:title="Popup menu item 2"/&gt; &lt;item android:id="@+id/menu3" android:title="Popup menu item 3"/&gt; &lt;/group&gt; &lt;/menu&gt; </code></pre> <p>My action bar button .xml</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/inverse" android:showAsAction="always|withText" android:title="Week" android:titleCondensed="Week" /&gt; &lt;/menu&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload