操作栏项目未找到ID

时间:2014-06-17 14:34:01

标签: android android-actionbar

我正在关注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);
    }


}

0 个答案:

没有答案