You can use reflection. Put the following code in the class, and then call Foo.isInOverflow(yourMenuItem);
protected static final String SUPPORTCLASS = "android.support.v7.internal.view.menu.MenuItemImpl"; protected static final String NATIVECLASS = "com.android.internal.view.menu.MenuItemImpl"; protected static Method sSupportIsActionButton; protected static Method sNativeIsActionButton; static { try { Class<?> MenuItemImpl = Class.forName(NATIVECLASS); sNativeIsActionButton = MenuItemImpl.getDeclaredMethod("isActionButton"); sNativeIsActionButton.setAccessible(true); } catch (Exception ignored) { } try { Class<?> MenuItemImpl = Class.forName(SUPPORTCLASS); sSupportIsActionButton = MenuItemImpl.getDeclaredMethod("isActionButton"); sSupportIsActionButton.setAccessible(true); } catch (Exception ignored) { } }
Note: you need to add the following line to your proguard configuration file for reflection to work in assemblies:
-keep public class android.support.v7.internal.view.menu.** { *; }
source share