简体   繁体   中英

Android Sherlock ActionBar Up button

在此输入图像描述

Near Stream there is a small arrow that takes u to the previous activity when clicked

I want to make the same in my app, I used

  getSupportActionBar().setDisplayHomeAsUpEnabled(true);

do I need to use 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

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() . The id for that button is 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

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. Removing onCreateOptionsMenu() for all activities which are not supposed to have these options should work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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