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?
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.
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.
PopupMenu popup = new PopupMenu(this, v);
what's "this" refer to ? the first parameter must be a context like Activity, not ApplicationContext!!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With