11111111111Dialog ide
Dialog log=new AlertDialog.Builder(Main2Activity.this)
.setMessage("內容")
.setTitle("標題")
.setPositiveButton("刪除", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {ui
}
})
.setNegativeButton("修改", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {this
}
}).create();
log.show();.net
222222222222ContextMenuget
registerForContextMenu(but);
it
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
//獲取菜單
getMenuInflater().inflate(R.menu.caidan,menu);
}io
@Override
public boolean onContextItemSelected(MenuItem item) {
switch (item.getItemId()){
case R.id.kaishi:
Toast.makeText(MainActivity.this, "開始", Toast.LENGTH_SHORT).show();
break;
case R.id.jieshu:
Toast.makeText(MainActivity.this, "結束", Toast.LENGTH_SHORT).show();
break;
}
return super.onContextItemSelected(item);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
menu.add(0,0,100,"背景");
menu.add(0,1,101,"音樂");
SubMenu subMenu = menu.addSubMenu(0, 2, 102, "設置");
subMenu.add(0,3,103,"設置音樂");
subMenu.add(0,4,104,"設置背景");
return super.onCreateOptionsMenu(menu);
}ast
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()){
case 0:
Toast.makeText(MainActivity.this, "背景", Toast.LENGTH_SHORT).show();
break;
case 1:
Toast.makeText(MainActivity.this, "音樂", Toast.LENGTH_SHORT).show();
break;
case 2:
Toast.makeText(MainActivity.this, "設置", Toast.LENGTH_SHORT).show();
break;
case 3:
Toast.makeText(MainActivity.this, "設置背景", Toast.LENGTH_SHORT).show();
break;
case 4:
Toast.makeText(MainActivity.this, "設置音樂", Toast.LENGTH_SHORT).show();
break;
}
return super.onOptionsItemSelected(item);
}class