【发布时间】:2016-05-25 23:16:07
【问题描述】:
我正在开发一个带有导航抽屉的应用程序。虽然我以前没有任何片段经验,但我可以成功实现抽屉导航。现在我的问题是,我想要一个操作栏后退按钮。我以前尝试过这个活动。但现在的问题是我有一个片段,里面有一个点击事件。当用户单击按钮时,它会转到其中包含列表视图的活动。现在我想使用操作栏向上按钮返回上一个片段。我该怎么做?当我按下手机上的返回按钮时,它工作正常。
我在列表视图活动中实现了 onOptionsItemSelected,如下所示。当我按下操作栏向上按钮时,它会进入登录窗口。不是我想去的地方。
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
switch (item.getItemId()) {
// Respond to the action bar's Up/Home button
case android.R.id.home:
Intent upIntent = NavUtils.getParentActivityIntent(this);
if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
// This activity is NOT part of this app's task, so create a new task
// when navigating up, with a synthesized back stack.
TaskStackBuilder.create(this)
// Add all of this activity's parents to the back stack
.addNextIntentWithParentStack(upIntent)
// Navigate up to the closest parent
.startActivities();
} else {
// This activity is part of this app's task, so simply
// navigate up to the logical parent activity.
NavUtils.navigateUpTo(this, upIntent);
}
return true;
}
return super.onOptionsItemSelected(item);
}
有人可以就这个问题提供一些帮助吗?
【问题讨论】:
标签: android android-fragments android-actionbar