JakeWharton / ActionBarSherlock

[DEPRECATED] Action bar implementation which uses the native action bar on Android 4.0+ and a custom implementation on pre-4.0 through a single API and theme.
http://actionbarsherlock.com
Apache License 2.0
7.1k stars 3.53k forks source link

MenuVisibilityListener not firing in compatibility mode. #847

Open dhaag opened 11 years ago

dhaag commented 11 years ago

When I add a menu visibility listener to the action bar, the listener only fires when showing a real action bar, and not the compatible one. I reproduced this on a Galaxy Nexus 4.2.2 where the onMenuVisibilityChanged() listener is called and on a Motorola Atrix 2.3.6, where the onMenuVisibilityChanged() listener is NOT called.

A fix for this which seems to work is to add the following code to ActionBarSherlockCompat.java

@Override
public boolean onOpenSubMenu(MenuBuilder subMenu) {
    aActionBar.dispatchMenuVisibilityChanged(true);     // ### Newly added ### 
    return true;
}

@Override
public void onCloseMenu(MenuBuilder menu, boolean allMenusAreClosing) {
    aActionBar.dispatchMenuVisibilityChanged(false);     // ### Newly added ### 
    checkCloseActionMenu(menu);
}

I've only had minimal time looking at the ActionBarSherlock code, so I'm not all that confident this is the best way to fix this.

iNoles commented 11 years ago

Did you called addOnMenuVisibilityListener methods with OnMenuVisibilityListener parameters? There is also removeOnMenuVisibilityListener too

dhaag commented 11 years ago

Well, sure I added the listener OnMenuVisibilityListener. That's how I figured out it was working on a new JB device, but then not on the older GB device.