请指导我如何在案例中调用不同的活动,而不是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;
}
}发布于 2011-04-28 20:55:03
@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;
}发布于 2011-04-28 20:44:31
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;https://stackoverflow.com/questions/5818736
复制相似问题