我想用操作栏显示我的菜单,但我的菜单不会显示,这是我的源代码:
public class EpolicyMainActivity extends TabActivity {
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
//hide title bar
BasicDisplaySettings.toggleTaskBar(EpolicyMainActivity.this, false);
//show status bar
BasicDisplaySettings.toggleStatusBar(EpolicyMainActivity.this, true);
super.onCreate(savedInstanceState);
setContentView(R.layout.menu);
Resources res = getResources(); // Resource object to get Drawables
TabHost tabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Resusable TabSpec for each tab
Intent intent; // Reusable Intent for each tab
// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this, LoginActivity.class);
spec = tabHost.newTabSpec("Login").setIndicator("",
res.getDrawable(R.drawable.epolicy_menu_xml_home))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, NABActivity.class);
spec = tabHost.newTabSpec("NAB").setIndicator("",
res.getDrawable(R.drawable.epolicy_menu_xml_nab))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, ContactActivity.class);
spec = tabHost.newTabSpec("Contact").setIndicator("",
res.getDrawable(R.drawable.epolicy_menu_xml_contact))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, AgenActivity.class);
spec = tabHost.newTabSpec("Agen").setIndicator("",
res.getDrawable(R.drawable.epolicy_menu_xml_agen))
.setContent(intent);
tabHost.addTab(spec);
for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++){
tabHost.getTabWidget().getChildAt(i).setPadding(0,0,0,0);
tabHost.getTabWidget().getChildTabViewAt(i).setBackgroundDrawable(null);
}
tabHost.setCurrentTab(0);
}
public boolean onCreateOptionsMenu(Menu menu)
{
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return super.onCreateOptionsMenu(menu);
}
public boolean onOptionsItemSelected(MenuItem item) {
super.onOptionsItemSelected(item);
switch (item.getItemId()) {
case R.id.menu_bantuan:
Intent itAbout = new Intent(EpolicyMainActivity.this, EpolicyBantuan.class);
itAbout.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(itAbout);
break;
case R.id.menu_exit:
dialogExit();
break;
case R.id.menu_logout:
dialogSignOut();
break;
}
return true;
}
public void dialogSignOut()
{
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Apakah anda ingin sign-out?")
.setCancelable(false)
.setPositiveButton("Ya", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Intent itSignOut = new Intent(EpolicyMainActivity.this, LoginActivity.class);
itSignOut.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(itSignOut);
finish();
}
})
.setNegativeButton("Tidak", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
}
public void dialogExit()
{
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Apakah anda ingin keluar?")
.setCancelable(false)
.setPositiveButton("Ya", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Intent itSplashEnd = new Intent(EpolicyMainActivity.this, SplashOutActivity.class);
itSplashEnd.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
itSplashEnd.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(itSplashEnd);
finish();
}
})
.setNegativeButton("Tidak", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
}
@Override
public void onBackPressed() {
dialogExit();
}
这是我的 menu.xml :
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/menu_bantuan"
android:title="@string/menu_bantuan"
android:orderInCategory="100"
android:showAsAction="ifRoom|withText"/>
<item android:id="@+id/menu_exit"
android:title="@string/menu_exit"
android:orderInCategory="100"
android:showAsAction="ifRoom|withText" />
<item android:id="@+id/menu_logout"
android:title="@string/menu_logout"
android:orderInCategory="100"
android:showAsAction="ifRoom|withText" />
在我的主布局中,我正在使用标题,这是否会影响我的菜单,所以我的菜单不会显示或其他任何东西?