问题
I have a fragment which is made using PreferenceFragment ,where I am overriding onOptionsMenuClosed(). But , its the callback is not coming to it.Neither is the call back coming to OnMenuOpened(), OnPanelCosed()...
This is what i have alredy tired.
@Override
public void onOptionsMenuClosed(Menu menu) {
// TODO Auto-generated method stub
Log.e(TAG, "close optionmenu");
super.onOptionsMenuClosed(menu);
}
and for onPanelClosed this is what i am trying.
@Override
public void onPanelClosed(int featureId, Menu menu) {
Log.e(TAG,"on panel closed the feature id is vivek "+featureId);
super.onPanelClosed(featureId, menu);
}
and when i do that for onPanelClosed(), Please help me out with this..
Please suggest where i am getting it wrong. and is tere any other way to catch if menu is closed without selecting any option.
回答1:
i finally found a solution for this :).. this is what is did.
public boolean isOverflowMenuOpen = false;
@Override
public void onActivityCreated(Bundle savedInstanceState) {
Activity activity = getActivity();
activity.getActionBar().addOnMenuVisibilityListener(new OnMenuVisibilityListener() {
@Override
public void onMenuVisibilityChanged(boolean isVisible) {
// TODO Auto-generated method stub
isOverflowMenuOpen = isOverflowMenuOpen ? false : true;
}
});
now from the variable isOverflowMenuOpen i can track if the overflow menu is open or not.
来源:https://stackoverflow.com/questions/24989278/no-callback-to-onoptionsmenuclosed-and-getting-error-in-overriding-onpanelclo