请指导我如何在案件中调用不同的活动而不是Toast,并且每个活动都应该显示菜单。另外,我想要同样的背景,如壁纸或其他所有活动。谢谢
这是代码
package com.droidnova.android.howto.optionmenu;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.Toast;
public class SimpleOptionMenu extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.settings: Toast.makeText(this, "You pressed the icon!", Toast.LENGTH_LONG).show();
break;
case R.id.services: Toast.makeText(this, "You pressed the text!", Toast.LENGTH_LONG).show();
break;
case R.id.icontext: Toast.makeText(this, "You pressed the icon and text!", Toast.LENGTH_LONG).show();
break;
}
return true;
}
}
答案 0 :(得分:3)
case R.id.settings:
Intent intent = new Intent(this, SettingsActivity.class);
startActivity(intent);
break;
case R.id.services:
Intent intent = new Intent(this, ServicesActivity.class);
startActivity(intent);
break;
case R.id.icontext:
Intent intent = new Intent(this, ThirdActivity.class);
startActivity(intent);
break;
答案 1 :(得分:3)
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
switch (item.getItemId())
{
case R.id.settings:
Intent intent = new Intent(this, firstclass.class);
startActivity(intent);
break;
case R.id.services:
Intent intent = new Intent(this, secondclass.class);
startActivity(intent);
break;
case R.id.icontext:
Intent intent = new Intent(this, thirdclass.class);
startActivity(intent);
break;
}
return true;
}