ActionBarSherlock: how to access home button view?

2020-02-26 01:41发布

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

Home Button like in 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.

1条回答
Summer. ? 凉城
2楼-- · 2020-02-26 02:20

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 (e.g., 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.
查看更多
登录 后发表回答