android.R.id.home 找不到符号

标签 android android-resources

我在 AppCompat 库中使用了 Toolbar 组件而不是 Default Actionbar。

编译时间:我得到找不到符号 android.R.id.home 的编译错误

public void setupActionBar() {
    // Set a Toolbar to replace the ActionBar.
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setHomeButtonEnabled(true);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    int id = item.getItemId();
    if(id == R.id.action_help) {
        showHelp();
        return true;
    }else if(id == android.R.id.home){
        Log.d(TAG, "Back Button clicked!");
        this.finish();
        return true;
    }

    return super.onOptionsItemSelected(item);
}

最佳答案

android.R.id.home 是在 API 级别 11 中引入的。 这里有更多细节: https://stackoverflow.com/a/18719090/2178694

关于android.R.id.home 找不到符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34575183/

相关文章:

android - 根据 fragment 宽度而不是屏幕宽度加载布局

android - 在可绘制资源 xml 中为 VectorDrawable 着色

eclipse - Lint : How to ignore "<key> is not translated in <language>" errors?

android - 按名称加载可绘制对象

android - 点击声音无法播放android onClick

android - 将数据广播到 Flutter 中的多个小部件

android - 有没有办法自定义 Android 铃声选择器对话框?

android - 如何将数据从 Activity 类转发到 View?

android - Gradle 同步失败 : connection time out: consult IDE log for more details

android - 佛兰德语语言代码