How do I know when the action bar menu opens?

I have a menu with the usual action:

This is what looks like Java:

getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);

ActionBar.OnNavigationListener navigationListener = new OnNavigationListener() {
    @Override
    public boolean onNavigationItemSelected(int itemPosition, long itemId) {
        //when an item is selected (i.e local/My Places/etc)
        return false;
    }
};

ArrayAdapter<String> adapter = new ArrayAdapter<String>(getBaseContext(), android.R.layout.simple_spinner_dropdown_item, new String[] { "Local", "My Places", "Checkins", "Latitude" });

getActionBar().setListNavigationCallbacks(adapter, navigationListener);

The callback for when the item is selected works fine, but I need a callback when the drop-down list opens / closes.

I looked ActionBar.OnMenuVisibilityListener, but the following does not print on my console.

ActionBar.OnMenuVisibilityListener listener = new ActionBar.OnMenuVisibilityListener() {
    @Override
    public void onMenuVisibilityChanged(boolean isVisible) {
        System.out.println("hello world!");
    };
};

getActionBar().addOnMenuVisibilityListener(listener);

What can I try next?

+4
source share
1 answer

Recently, I faced the same problem. And I use the same method to show Spinner.

Spinner . Spinner xml .

<com.company.yourapp.View.MenuSpinner
        android:id="@+id/catalogue_menu_spinner"
        android:layout_width="wrap_content"
        android:layout_height="?attr/actionBarSize"
        android:layout_alignParentLeft="true"
        android:layout_below="@id/catalogue_status_bar"
        android:background="@null"
        android:layout_marginLeft="60dp" />

, , (MenuSpinner ) .

, -, , , .

0

All Articles