简体   繁体   中英

ActionBarSherlock: how to access home button view?

I am using ActionBarSherlock and want a similiar functionality of the home button as it is known by Google Maps.

像Google Maps中的主页按钮

I already managed to open a QuickAction ( http://code.google.com/p/simple-quickactions/ ) when pressing the home button with this piece of code:

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
       View anchor = findViewById(R.id.text); // how do I get the home button view here?
       quickAction.show(anchor);
       return true;
    }
    return false;
}

However I am using a simple TextView of the activity as an anchor (R.id.text). How do I retrieve the home button view from the ActionBar there?

Oh, and findViewById(android.R.id.home) or findViewById(item.getItemId()) both return null.

You cannot access the home view because it exists above the content view and in the window decoration.

Google uses a custom action bar on pre-Honeycomb devices which exists inside the content view. This is what allows them to make this custom dropdown. On Honeycomb and newer they use a highly customized version of list navigation in the system action bar.

Since you are using ActionBarSherlock you have two options:

  1. Go for the newer style navigation and customize the built-in list navigation.
  2. Supply a custom navigation view which mimics the home view (eg, has your app icon in it). With this custom view you will be able to provide an anchor on which the custom popup menu can be attached.

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