Pro7Activity.java
package ps.pro7;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ContextMenu.ContextMenuInfo;
import android.widget.AbsoluteLayout;
@SuppressWarnings("deprecation")
public class Pro7Activity extends Activity {
/**
* www.master-gtu.blogspot.com
* pankaj sharma(8460479175),
* chavda vijay(8460420769)
*/
AbsoluteLayout al;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
al=(AbsoluteLayout) findViewById(R.id.alayout);
al.setOnCreateContextMenuListener(this);
}
public void createMenu(Menu menu)
{
MenuItem m1=menu.add(0,0,0,"RED");
m1.setAlphabeticShortcut('r');
m1.setIcon(R.drawable.icon);
MenuItem m2=menu.add(0,1,1,"GREEN");
m2.setAlphabeticShortcut('g');
m1.setIcon(R.drawable.icon);
MenuItem m3=menu.add(0,2,2,"BLUE");
m3.setAlphabeticShortcut('b');
m1.setIcon(R.drawable.icon);
}
public void listenMenu(MenuItem item)
{
int id=item.getItemId();
switch(id)
{
case 0:
al.setBackgroundColor(Color.RED);
break;
case 1:
al.setBackgroundColor(Color.GREEN);
break;
case 2:
al.setBackgroundColor(Color.BLUE);
break;
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// TODO Auto-generated method stub
super.onCreateOptionsMenu(menu);
createMenu(menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
super.onOptionsItemSelected(item);
listenMenu(item);
return true;
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
// TODO Auto-generated method stub
super.onCreateContextMenu(menu, v, menuInfo);
createMenu(menu);
}
@Override
public boolean onContextItemSelected(MenuItem item) {
// TODO Auto-generated method stub
super.onContextItemSelected(item);
listenMenu(item);
return true;
}
}
No comments:
Post a Comment