리플렉션을 사용할 수 있습니다. 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) {
}
}
// --------------------------------------------------------------------------------------------
/**
* Check if an item is showing (not in the overflow menu).
*
* @param item
* the MenuItem.
* @return {@code true} if the MenuItem is visible on the ActionBar.
*/
public static boolean isActionButton(MenuItem item) {
switch (item.getClass().getName()) {
case SUPPORTCLASS:
try {
return (boolean) sSupportIsActionButton.invoke(item, (Object[]) null);
} catch (Exception e) {
// fall through
}
case NATIVECLASS:
try {
return (boolean) sNativeIsActionButton.invoke(item, (Object[]) null);
} catch (Exception e) {
// fall through
}
default:
return true;
}
}
/**
* Check if an item is in the overflow menu.
*
* @param item
* the MenuItem
* @return {@code true} if the MenuItem is in the overflow menu.
* @see #isActionButton(MenuItem)
*/
public static boolean isInOverflow(MenuItem item) {
return !isActionButton(item);
}
참고 클래스에 다음 코드를 삽입 한 후 호출 : 반사 생산에서 작동, 그래서 당신은 당신의 난독 구성 파일에 다음 줄을 추가해야하는 빌드 :
는
-keep public class android.support.v7.internal.view.menu.** { *; }
아이콘이 표시되지 않습니다 오버플로 메뉴 항목에서 – superfell
나는 그들이 그렇지 않다는 것을 안다. 그건 내가 묻는 것이 아니야. 나는 프리 허니 콤 장치 (메뉴 아이콘 보여주기)에 관심이 있다고 지적했다. – Sababado
오버 플로우 메뉴에있는 MenuItems의 아이콘을 비활성화하여 기존 메뉴에 텍스트 만 표시되도록하는 방법을 찾으면 도움이 될 것입니다. –