Android Concise Development Tutorial 14: Context Menu Drawing geometry

Source: Internet
Author: User
Tags pear

Context-sensitive menus (context menu) are the menus that are displayed on the right mouse button on a PC, and are long pressed on the Android platform to activate the contextual Menu,context menu, which is typically used to display menus related to current UI content.

The use of context menu is very similar to option menu:

The first is to create a menu resource, a new menu_context_shape.xml under Res/menu to display the oval,pear,shape2d:

<?xml version= "1.0″encoding=" utf-8″?>
<menu
Xmlns:android= "Http://schemas.android.com/apk/res/android" >
<item
Android:id= "@+id/mnuoval"
android:title= "Oval" >
</item>
<item
Android:id= "@+id/mnupear"
android:title= "Pear" >
</item>
<item
Android:id= "@+id/mnushape2ddemo"
android:title= "Shape2d" >
</item>
</menu>

Expand the context Menu by using the Oncreatecontextmenu method:

@Override
public void Oncreatecontextmenu (ContextMenu menu, View V,
Contextmenuinfo menuinfo) {
Super.oncreatecontextmenu (menu, V, menuinfo);
Menuinflater inflater = Getmenuinflater ();
Inflater.inflate (R.menu.menu_context_shape, menu);
}

To handle the context menu event:

@Override
public boolean oncontextitemselected (MenuItem item) {
Menuoption = Item.getitemid ();
DrawImage ();
return super.oncontextitemselected (item);
}

In order to display the context menu on the view in a long time, you need to register the context menu for view:

public void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Registerforcontextmenu (Graphic2dview);
}

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.