0

how can I get the View Anchor for a PopupMenu if the corresponding MenuItem in ActionView is not shown as Action:

if (item.getItemId() == R.id.myMenu) {
        PopupMenu popupMenu = new PopupMenu (this, findViewById(R.id.myMenu));
        popupMenu.show();
        return true;
    }

    <item
        android:id="@+id/myMenu"
        appcompat:showAsAction="never"
        android:title="@string/sharePage"
        android:icon="@drawable/navigation_share"/>

If appcompat:showAsAction="always"
everything works fine, but with
appcompat:showAsAction="never" the Method findViewById(R.id.myMenu) returns null.

Thommy
  • 5,070
  • 2
  • 28
  • 51
  • remove that `appcompat:showAsAction="never"` – Cyph3rCod3r Oct 09 '13 at 08:45
  • But what if I don't want it to show as action? – Thommy Oct 09 '13 at 09:48
  • can you elaborate more what exactly your trying to say . All i know is a popupmenu have an anchor view and if anchor view or action is not visible then the popup menu will not be shown – Cyph3rCod3r Oct 09 '13 at 10:06
  • I'm trying to open a PopupMenu from an non-Action View, so basically with the Menu-Button (the three dots) as Anchor. – Thommy Oct 10 '13 at 07:09
  • ohh !! so your using action bar or not, cause action bar has default overflow menu in which it will open your popup menu automatically ? tell? – Cyph3rCod3r Oct 10 '13 at 09:40
  • Yeah i know that, but I have my own PopupMenu which should be opened after clicking on one item of ActionBars popupmenu (submenu) – Thommy Oct 10 '13 at 09:45
  • What about to put a group into the MenuItem in xml? It might be a way to customize it later, I guess. – Blo May 12 '14 at 22:22
  • Look at this answer: [StackOverflow](http://stackoverflow.com/questions/14729592/show-popup-menu-on-actionbar-item-click) – Andre Rocha Jun 24 '14 at 00:30
  • I solved it with SubMenu. – Thommy Jun 24 '14 at 13:32

0 Answers0