我正在尝试创建一个选项菜单,它会向我显示菜单,但是当我单击它所做的任何事情时,它现在会向我显示 Toast.makeText 文本,我的代码在下面。但是当我将代码放在同一个活动中时,它会向我显示文本。
package com.officextracts.kaspersky;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
public class Option_menu extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_option_menu);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.option_menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
switch (item.getItemId())
{
case R.id.menu_home:
// Single menu item is selected do something
// Ex: launching new activity/screen or show alert message
Toast.makeText(this, "Home Is selected", Toast.LENGTH_SHORT).show();
return true;
case R.id.menu_krp:
Toast.makeText(this, "Kaspersky Retail Products", Toast.LENGTH_SHORT).show();
return true;
case R.id.menu_kep:
Toast.makeText(this, "Kaspersky Endpoint Products", Toast.LENGTH_SHORT).show();
return true;
case R.id.menu_fkr:
Toast.makeText(this, "Find Kaspersky Resaller", Toast.LENGTH_SHORT).show();
return true;
case R.id.menu_sales:
Toast.makeText(this, "Contact Kaspersky Sales", Toast.LENGTH_SHORT).show();
return true;
case R.id.menu_crs:
Toast.makeText(this, "Contact Retail Support", Toast.LENGTH_SHORT).show();
return true;
case R.id.menu_ces:
Toast.makeText(this, "Contact Enterprise Support", Toast.LENGTH_SHORT).show();
return true;
case R.id.menu_coo:
Toast.makeText(this, "Contact Our Office", Toast.LENGTH_SHORT).show();
return true;
case R.id.menu_sms:
Toast.makeText(this, "SMS for Support", Toast.LENGTH_SHORT).show();
return true;
case R.id.menu_email:
Toast.makeText(this, "Email Support", Toast.LENGTH_SHORT).show();
return true;
case R.id.menu_exit:
finish();
System.exit(0);
default:
return super.onOptionsItemSelected(item);
}
}
}
现在怎么做呢,你可以看到菜单底部有一个退出按钮,当我从其他活动调用它但从相同的活动它工作时它现在工作。
我是android新手,请详细解释一下..
感谢您