Java – How do I know when the action bar menu expands?

How do I know when the action bar menu expands?… here is a solution to the problem.

How do I know when the action bar menu expands?

I have a normal action bar menu like this :

This is what it looks like in Java:


ActionBar.OnNavigationListener navigationListener = new OnNavigationListener() {
    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

when selecting an item works fine, but I want the callback when opening / closing the drop-down menu.

I looked at ActionBar.OnMenuVisibilityListener, but the following command doesn’t print anything in my console.

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


What can I try next?


Recently I was faced with the same task. I use the same method to display Spinner.

But to fix this, I have to replace this Spinner with a custom one. I removed this code and placed my own Spinner through the xml layout of my activity.

        android:layout_marginLeft="60dp" />

Notify my class (MenuSpinner in the code above) when the menu is displayed from me this gets the problem.

I hope my answer helps people like me who insist on this.

Related Problems and Solutions