【问题标题】:What might be preventing the HomeAsUp icon being displayed什么可能会阻止 HomeAsUp 图标显示
【发布时间】:2014-12-18 15:18:17
【问题描述】:

我一直在开发具有多个 ActionBar 活动的应用程序,并且从一开始 HomeAsUp 按钮就可见并且正在处理从 MainActivity 中选择的所有活动。今天我注意到它不再存在 - 但我无法弄清楚我所做的更改会影响它。

最近几天最重要的变化是我将项目从 Eclipse 迁移到 Android Studio,因为 Eclipse 经常损坏我的项目文件并需要完全重新安装。

这是创建新活动的主活动中的代码示例:

@Override
public boolean onOptionsItemSelected(MenuItem item) {
  Intent intent=null;
  int id = item.getItemId();
  switch (id) {
    case R.id.action_list:
      intent = new Intent(this, StudyListActivity.class);
      break;
    // etc
  }

  if (intent != null) {
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivity(intent);
    return true;
  }
  return super.onOptionsItemSelected(item);
}

这是清单中的意图声明

<activity
  android:name="com.example.app.StudyListActivity"
  android:label="@string/activity_list"

  android:parentActivityName="com.example.app.MainActivity" >
    <meta-data
      android:name="android.support.PARENT_ACTIVITY"
      android:value="com.example.app.MainActivity" />
</activity>

由于它停止工作,我也尝试过放置

getSupportActionBar().setHomeButtonEnabled(true);

在被调用活动的 onCreate 方法中(根据Display back button on action bar),但这没有区别。

所以我想知道在我从 eclipse 的迁移中是否有任何东西被剥离,这会阻止它显示(或者我可以改变的其他东西可能会无意中禁用它)

【问题讨论】:

    标签: java android android-actionbar


    【解决方案1】:

    你应该通过setDisplayOptions启用它

    getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_HOME);
    

    【讨论】:

      【解决方案2】:

      你也可以试试

      getSupportActionBar().setDisplayHomeAsUpEnabled(true);
      

      在你想要 HomeAsUp 图标的活动中

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-04-20
        • 2010-10-24
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多