我正在关注Adding Action Button
的{{1}}教程,我遇到了另一个问题。当我使用devolper.android.com
引用操作栏ID时,它表示它不存在,但R.id.action_search
显示正常......?
onOptionsItemSelected方法:
R.id.action_settings
main.xml中:
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
//int id = item.getItemId();
//if (id == R.id.action_settings) {
//return true;
//}
//return super.onOptionsItemSelected(item);
switch (item.getItemId()) {
case R.id.action_search:
openSearch();
return true;
case R.id.action_settings:
openSettings();
return true;
default:
return super.onOptionsItemSelected(item);
}
}