简体   繁体   English

Android Sherlock ActionBar Up按钮

[英]Android Sherlock ActionBar Up button

在此输入图像描述

Near Stream there is a small arrow that takes u to the previous activity when clicked 在Stream附近有一个小箭头,可以在点击时将您带到上一个活动

I want to make the same in my app, I used 我想在我的应用程序中使用相同的内容

  getSupportActionBar().setDisplayHomeAsUpEnabled(true);

do I need to use onOptionsItemSelected ? 我需要使用onOptionsItemSelected吗?

The arrow is appearing, but nothing happens once clicked. 箭头出现,但点击后没有任何反应。

And I have two Items in my menu, they appear everywhere where I call OnCreateOptionsMenu 我的菜单中有两个项目,它们出现在我调用OnCreateOptionsMenu任何地方

this is my item code where I want to to appear only in my last activity, How ? 这是我的项目代码,我想只在我的上一个活动中出现,如何?

      <item 
android:id="@+id/bAbout"
android:title="About"
android:showAsAction="always"/>

Yes you have to implement onOptionsItemSelected() . 是的,你必须实现onOptionsItemSelected() The id for that button is android.R.id.home 该按钮的id是android.R.id.home

public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {

    case android.R.id.home:
         // Do whatever you want, e.g. finish()
         break;

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

And I have two Items in my menu, they appear everywhere where I call OnCreateOptionsMenu 我的菜单中有两个项目,它们出现在我调用OnCreateOptionsMenu的任何地方

I'm not sure what the problem here is. 我不确定这里的问题是什么。 Of course you should only implement onCreateOptionsMenu() and inflate that menu resource where you want it. 当然,您应该只实现onCreateOptionsMenu()并在您想要的地方夸大该菜单资源。 Removing onCreateOptionsMenu() for all activities which are not supposed to have these options should work. 删除不应该具有这些选项的所有活动的onCreateOptionsMenu()应该有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM