5th chapter (7) Popup menu (popup Menus)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.