Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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.

like image 692
Konsumierer Avatar asked Apr 17 '12 08:04

Konsumierer


1 Answers

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.
like image 128
Jake Wharton Avatar answered Sep 25 '22 14:09

Jake Wharton