//called when hardware button "Menu" clicked
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
然后这个
@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_options:
startActivity(new Intent(this, EditPreferences.class));
break;
case R.id.menu_about:
Dialog dialog = new Dialog(getApplicationContext());
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);//NO TITLE :)
dialog.setContentView(R.layout.menu_about);
dialog.setCancelable(true);
dialog.show();
break;
default:
break;
}
//return true;
//return false;
return super.onMenuItemSelected(featureId, item);
}
使用调试我看到我输入开关案例R.id.menu_about ,但 dialog.show()没有做任何事情
对话框刚刚显示,我尝试使用标准的AlertDialog,也没有运气
答案 0 :(得分:8)
尝试改变:
Dialog dialog = new Dialog(getApplicationContext());
到
Dialog dialog = new Dialog(this);