Category: C #, Android, VS2015;
Date Created: 2016-02-07 I. INTRODUCTION
Function Description: The user clicks the button popup menu. When the user selects a menu item, the Menuitemclick event is triggered and the popup menu disappears, and if the user clicks outside the menu, the popup menu disappears directly. When the menu disappears, the Dismissevent event is raised (this event can be used to do some subsequent processing when the menu disappears). Second, example 7--Demo07popupmenu
1. Operation effect
2. Add Menu item
Add a menu subfolder under the Resources folder, and then add a file named Demo07_popup_menu.xml under this subfolder:
<?XML version= "1.0" encoding= "Utf-8"?><Menuxmlns:android= "Http://schemas.android.com/apk/res/android"> <ItemAndroid:id= "@+id/item1"Android:title= "Item 1" /> <ItemAndroid:id= "@+id/item1"Android:title= "Item 2" /> <ItemAndroid:id= "@+id/item1"Android:title= "Item 3" /></Menu>
3. Add Demo07_popupmenu.axml
<?XML version= "1.0" encoding= "Utf-8"?><LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"android:orientation= "vertical"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent"> <ButtonAndroid:id= "@+id/popupbutton"Android:layout_width= "Fill_parent"Android:layout_height= "Wrap_content"Android:text= "@string/showpopup" /></LinearLayout>
Save all files.
4. Add Demo07PopupMenu.cs
usingAndroid.app;usingAndroid.os;usingAndroid.widget;namespaceCh05demos. srcactivity{[Activity (Label="Demo07popupmenu")] Public classdemo07popupmenu:activity {protected Override voidOnCreate (Bundle savedinstancestate) {Base. OnCreate (savedinstancestate); Setcontentview (Resource.Layout.demo07_Popup); Button btn= findviewbyid<button>(Resource.Id.popupButton); Btn. Click+ = (s, arg) = ={popupmenu Menu=NewPopupMenu ( This, BTN); Menu. Inflate (Resource.Menu.demo07_popup_menu); Menu. Menuitemclick+ = (sender, args) = = { stringstr =string. Format ("you have selected: {0}", args. Item); Toast.maketext ( This, str, toastlength.short). Show (); }; Menu. Dismissevent+ = (sender, args) = = { //after the menu disappears, you can do some post-processing in this event }; Menu. Show (); }; } }}
Run the observation effect.
5th chapter (7) Popup menu (popup Menus)