This example for you to share the Android pop-up menu effect of the specific code for your reference, the specific content as follows
function Description: The user clicks the button pop-up menu. When the user selects a menu item, the Menuitemclick event is triggered and the pop-up menu disappears; If the user clicks outside the menu, the pop-up menu disappears directly. When the menu disappears, a dismissevent event is raised (this event can be used to do some post-processing when the menu disappears).
1. Operation effect
2. Add menu items
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"?> <menu xmlns:android=
"http://schemas.android.com/apk/res/" Android ">
<item android:id=" @+id/item1 "
android:title=" Item 1,/> <item android:id=
"@+id/ Item1 "
android:title=" Item 2/>
<item android:id= "@+id/item1"
android:title= "Item 3"/>
</menu>
3, add Demo07_popupmenu.axml
<?xml version= "1.0" encoding= "Utf-8"?> <linearlayout xmlns:android=
"http://schemas.android.com/apk/" Res/android "
android:orientation=" vertical "
android:layout_width=" fill_parent "
android:layout_" height= "Fill_parent" >
<button
android: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
using Android.app; using Android.os; using Android.widget; Namespace Ch05demos. srcactivity {[Activity (Label = ' demo07popupmenu ')] public class Demo07popupmenu:activity {protected override void OnCreate (Bundle savedinstancestate) {base.
OnCreate (savedinstancestate);
Setcontentview (Resource.Layout.demo07_Popup);
Button btn = findviewbyid<button> (Resource.Id.popupButton); Btn.
Click + = (s, arg) => {popupmenu menu = new PopupMenu (this, BTN); Menu.
Inflate (Resource.Menu.demo07_popup_menu); Menu. Menuitemclick = = (sender, args) => {string str = string. Format ("you selected: {0}", args.)
Item); Toast.maketext (This,str, Toastlength.short).
Show ();
}; Menu.
Dismissevent + = (sender, args) => {//menu disappears to do some post-processing in this event}; Menu.
Show ();
}; }
}
}
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.