gpt4 book ai didi

android - ActionBarSherlock:OnOptionsItemSelected 无法识别 R.id.home

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:57:16 26 4
gpt4 key购买 nike

我正在使用 ActionBarSherlock 库,并且按照建议的确切步骤进行操作 herehere启用导航到上一个屏幕。

我的代码是这样的:

getSupportActionBar().setDisplayHomeAsUpEnabled(true);

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// This callback is used only when mSoloFragment == true (see
// onActivityCreated above)
switch (item.getItemId()) {
case android.R.id.home:
// App icon in Action Bar clicked; go up
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); // Reuse the
// existing
// instance
startActivity(intent);

return true;
default:
return super.onOptionsItemSelected(item);
}

但 R.id.home 未被识别,home 显示为红色。 :-/如果我使用 native 操作栏,主页声明会将我带到 ids.xml 文件。但是这里的声明在我使用 ActionBarSherlock Activity 时找不到。我错过了什么吗?

最佳答案

只是替换这个

android.R.id.home

R.id.home

然后检查你的代码……运行它

因为

R.layout.* 是您提供的布局(例如在 res/layout 中)。

android.R.layout.* 是 Android SDK 附带的布局。

关于android - ActionBarSherlock:OnOptionsItemSelected 无法识别 R.id.home,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15565864/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com