我是android的noob,我使用ActionBarSherlock的菜单栏访问菜单。在Android API低于API 11的情况下,一切正常,但对于任何API 11和以上版本,菜单栏/菜单项都没有响应。菜单项突出显示,当我点击他们,但他们不执行。就好像菜单项已经失去了他们的听众是否有一个我忘了实现的设置?任何帮助是极大的赞赏。为什么ActionBarSherlock没有响应?
我的代码:
//My Sherlock wrapper
ActionBarSherlock mSherlock = ActionBarSherlock.wrap(this);
//OnCreate
setTheme(R.style.Theme_Sherlock);
mSherlock.setContentView(R.layout.main);
//Menu Methods
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
switch (item.getItemId())
{
case 1: // id from the xml file
Intent i = new Intent("com.bmoney.GSCC.OPTIONS");
startActivity(i);
return true; // we handled the click, dont pass it up the chain
case 2: // id from the xml file
Intent i2 = new Intent("com.bmoney.GSCC.PREFS");
startActivity(i2);
return true;
}
return false;
}
@Override
public boolean onCreateOptionsMenu(android.view.Menu menu) {
// TODO Auto-generated method stub
return mSherlock.dispatchCreateOptionsMenu(menu);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) { //<-- has Sherlock Menu Import
menu.add(0,1,0,"Preferences").setIcon(R.drawable.ic_action_example).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
menu.add(0,2,0,"Help").setIcon(R.drawable.info).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
return true;
}
感谢您的回应。我的menuitem impot已经是sherlock的等价物。我遵循了您的建议,但是当我整合我的OnCreateOptionsMenu时,菜单项不会出现在菜单栏中。请检查我的编辑。我做错什么了吗? – 2013-02-20 01:20:48
@ B.Money:除了科里斯科特的回答之外,没有什么可以想到的。以下是一个带有工作操作栏的示例应用程序:https://github.com/commonsguy/cw-omnibus/tree/master/ActionBar/ActionBarDemo – CommonsWare 2013-02-20 11:52:33