I\'ve implemented PopupMenu for a menu that is displayed after pressing an item on the ActionBar. I am wondering what alternatives there are for SDK versions before 11?
Alternatively, you could use a floating context menu.
(3 years later, actually reads that floating context menu only works for long clicks and hastily edits answer).
You'd need to register your view for the context menu, open the menu, then unregister it (so that long-clicks on the action item didn't trigger it again):
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.my_menu_item) {
View view = item.getActionView();
registerForContextMenu(view);
openContextMenu(view);
unregisterForContextMenu(view);
return true;
}
return super.onOptionsItemSelected(item);
}
and of course, implement onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo)
as per the documentation linked.
The better choice would be, as OP wrote, to use an AlertDialog in this particular case if you wanted a centred dialog, or a PopupMenu if you want the menu to be anchored to the action item. The popup menu might be weird though, because it'll feel like an overflow menu.