You can try to override the method
public void onCloseMenu(MenuBuilder menu, boolean allMenusAreClosing)
class PopupMenu . It is this method that calls setOnDismissListener() internally in API 14+. But to do this is not easy. The problem is that the com.android.internal.view.menu.MenuBuilder class is not included in the Android SDK, so you cannot compile your code if you try to import this class.
However, you can create your own βfakeβ implementation of this class, put it in the com.android.internal.view.menu package, make a .jar file with it, copy this βfake libraryβ to the libs folder and set the scope of this library to IntelliJ IDEA project settings as provided. This means that the classes in this jar file already have real devices (which is true), and you only need to compile your code for them. The basic idea here is that your fake MenuBuilder should be in the classpath to compile javac , but should not be included in the resulting .apk file.
This is a difficult decision, but it should work.
source share