package com.example.wenandroid;import android.app.Activity;import android.os.Bundle;import android.view.ContextMenu;import android.view.ContextMenu.ContextMenuInfo;import android.view.Menu;import android.view.MenuItem;import android.view.View;import android.widget.TextView;public class OptionMenuDemo extends Activity {private static final int MENU_ITEM_COUNTER=Menu.FIRST;private TextView mtextview;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.optionmenu);mtextview=(TextView)findViewById(R.id.mtextview);mtextview.setText("要大一點才能看清楚");registerForContextMenu(mtextview);}@Overridepublic void onCreateContextMenu(ContextMenu menu, View v,ContextMenuInfo menuInfo) {menu.add(0,MENU_ITEM_COUNTER+1,0,"白色");menu.add(0, MENU_ITEM_COUNTER+2, 0, "黃色");menu.add(0, MENU_ITEM_COUNTER+3, 0, "藍色");super.onCreateContextMenu(menu, v, menuInfo);}@Overridepublic boolean onContextItemSelected(MenuItem item) {switch(item.getItemId()){case MENU_ITEM_COUNTER+1:mtextview.setBackgroundResource(R.drawable.first);break;case MENU_ITEM_COUNTER+2:mtextview.setBackgroundResource(R.drawable.second);break;case MENU_ITEM_COUNTER+3:mtextview.setBackgroundResource(R.drawable.third);break;}return super.onContextItemSelected(item);}}