這是SherlockActionBar
示例,它使用靜態附件,我運行到ICE_CREAM_SANDWICH
設備,但方法onOptionsItemSelected
未被調用!onOptionsItemSelected在使用設備API級別14(SherlockActionBar)時不調用(SherlockActionBar)
代碼的多餘部分被刪除,3.x和2.x的版本試過沒有問題,幫幫我~~
@Override
protected void onCreate(Bundle savedInstanceState) {
setTheme(SampleList.THEME); // Used for theme switching in samples
super.onCreate(savedInstanceState);
mSherlock
.setUiOptions(ActivityInfo.UIOPTION_SPLIT_ACTION_BAR_WHEN_NARROW);
mSherlock.setContentView(R.layout.text);
((TextView) findViewById(R.id.text))
.setText(R.string.static_attach_content);
}
@Override
public boolean onCreateOptionsMenu(android.view.Menu menu) {
return mSherlock.dispatchCreateOptionsMenu(menu);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Used to put dark icons on light action bar
boolean isLight = SampleList.THEME == R.style.Theme_Sherlock_Light;
menu.add("Save")...
menu.add("Search")...
menu.add("Refresh")...
return true;
}
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if (mSherlock.dispatchKeyEvent(event)) {
return true;
}
return super.dispatchKeyEvent(event);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
Log.i("", "on options item selected!!!!!!!!!!!!!!!!");
Toast.makeText(this, item.toString(), Toast.LENGTH_SHORT).show();
return true;
}
}
你自定義視圖添加到您的菜單按鈕? –
@TomislavNovoselec這個樣本沒有添加。 – zkwlx
哦!!我發現!!我忘了覆蓋Activity.onOptionsItemSelected !!!! hahaha – zkwlx