Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android V7 Support Library Popup Menu

I'm trying to implement a PopupMenu with the Support V7 Library. All compiles fine but when I try to call:

    PopupMenu popup = new PopupMenu(this, v);
    popup.getMenu().add(Menu.NONE,MENU_SHARE_A,1,R.string.A);
    popup.getMenu().add(Menu.NONE,MENU_SHARE_B,2,R.string.B);
    popup.show();

an error occurs on call:

07-31 17:23:53.365: E/AndroidRuntime(14128): java.lang.RuntimeException: Binary XML file line #17: You must supply a layout_height attribute.

Which refers I think to "abc_popup_menu_item_layout.xml" with this element:

<android.support.v7.internal.view.menu.ListMenuItemView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="?attr/dropdownListPreferredItemHeight"
        android:minWidth="196dip"
        android:paddingRight="16dip">

Is this is a bug or do I do something wrong?

like image 916
LeDon Avatar asked Jul 31 '13 15:07

LeDon


People also ask

How do I show the pop up menu on Android?

Go to app > res > right-click > New > Android Resource Directory and give Directory name and Resource type as menu. Now, we will create a popup_menu file inside that menu resource directory. Go to app > res > menu > right-click > New > Menu Resource File and create a menu resource file and name it as popup_menu.

What is pop up menu in Android Studio?

A PopupMenu displays a Menu in a modal popup window anchored to a View . The popup will appear below the anchor view if there is room, or above it if there is not. If the IME is visible the popup will not overlap it until it is touched. Touching outside of the popup will dismiss it.


1 Answers

PopupMenu popup = new PopupMenu(this, v);

what's "this" refer to ? the first parameter must be a context like Activity, not ApplicationContext!!

like image 148
Alex Chan Avatar answered Sep 27 '22 19:09

Alex Chan