ContextMenu上下文菜单,它是通过长时间的按住一个view弹出来的菜单,比如长时间按住一个图片、文本等,都可以触发弹出一个上下文菜单。可以根据选择的菜单,弹出相应的消息或者跳转到相关的Activity中去。
public interface ContextMenu implements Menu
android.view.ContextMenu
Class Overview
Extension of Menu for context menus providing functionality to modify the header of the context menu.
Context menus do not support item shortcuts and item icons.
To show a context menu on long click, most clients will want to call registerForContextMenu(View) and override onCreateContextMenu(ContextMenu, View, ContextMenu.ContextMenuInfo).
开始我们的实验。
第一步、设计页面contextmenu.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android=" http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView android:id="@+id/imgHead" android:layout_width="wrap_content" android:src="@drawable/icon" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_alignParentLeft="true"></ImageView>
<TextView android:layout_width="wrap_content" android:id="@+id/tvName" android:layout_height="wrap_content" android:text="姓名
public interface ContextMenu implements Menu
android.view.ContextMenu
Class Overview
Extension of Menu for context menus providing functionality to modify the header of the context menu.
Context menus do not support item shortcuts and item icons.
To show a context menu on long click, most clients will want to call registerForContextMenu(View) and override onCreateContextMenu(ContextMenu, View, ContextMenu.ContextMenuInfo).
开始我们的实验。
第一步、设计页面contextmenu.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android=" http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView android:id="@+id/imgHead" android:layout_width="wrap_content" android:src="@drawable/icon" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_alignParentLeft="true"></ImageView>
<TextView android:layout_width="wrap_content" android:id="@+id/tvName" android:layout_height="wrap_content" android:text="姓名