PopupMenu菜单项显示图标:
加入头文件:
import java.lang.reflect.Field; import com.android.internal.view.menu.MenuPopupHelper;
加入反射:
try { Field field = mPopupMenu.getClass().getDeclaredField("mPopup"); field.setAccessible(true); MenuPopupHelper mHelper = (MenuPopupHelper) field.get(mPopupMenu); mHelper.setForceShowIcon(true); } catch (IllegalAccessException | NoSuchFieldException e) { e.printStackTrace(); }
//mPopupMenu.show();