1

How to show Popup menu always at bottom of the anchor view. This is the code I'm using to display popup menu.

 PopupMenu popup = new PopupMenu(activityReference, view, Gravity.NO_GRAVITY);
                popup.getMenuInflater()
                    .inflate(R.menu.popup_menu_event_edit, popup.getMenu());
popup.show();

I have tried changinging the Gravity.NO_GRAVITY to Gravity.BOTTOM. But its not working.

karthiKeyan B
  • 91
  • 1
  • 7

3 Answers3

0

It worked for me

PopupMenu attachFilePopup = new PopupMenu(this, view ,Gravity.BOTTOM);
attachFilePopup.inflate(R.menu.attachment_choices);

view => the bottom button where you want to show the menu

attachment_choices.xml

<item
    android:id="@+id/attach_location"
    android:title="@string/send_location"/>

<item
    android:id="@+id/attach_record_voice"
    android:title="@string/attach_record_voice"/>

<item
    android:id="@+id/attach_take_picture"
    android:title="@string/attach_take_picture"/>

<item
    android:id="@+id/attach_choose_picture"
    android:title="@string/attach_choose_picture"/>

<item
    android:id="@+id/attach_choose_file"
    android:title="@string/choose_file"/>

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
user9
  • 25
  • 1
  • 5
0

here button1 is anchor view means referrence where you want to show your menu

PopupMenu popupMenu = new PopupMenu(context, button1, Gravity.TOP);
popupMenu.getMenuInflater().inflate(R.menu.home_drawer_bottom_nav_menu, popupMenu.getMenu());
popupMenu.show();
saigopi.me
  • 14,011
  • 2
  • 83
  • 54
-1

Use this it is working for me.

popupMenu = new PopupMenu(MainActivity.this, anchorView);
popupMenu.inflate(R.menu.popup_menu);
            popupMenu.show();
Abhishek Akhani
  • 209
  • 1
  • 4
  • 9
  • My anchor view is at the center of the screen. So what happens the popup displays at the top of the anchor view even it has enough space at the bottom of the view – karthiKeyan B Jun 05 '15 at 15:07