1 2 3 4 5 6 7 8 9 10
| Field mPopup = popupMenu.getClass().getDeclaredField("mPopup"); mPopup.setAccessible(true); MenuPopupHelper helper = (MenuPopupHelper) mPopup.get(popupMenu); Class standardMenuPopup = Class.forName("androidx.appcompat.view.menu.StandardMenuPopup"); Field mHasContentWidth = standardMenuPopup.getDeclaredField("mHasContentWidth"); mHasContentWidth.setAccessible(true); mHasContentWidth.setBoolean(helper.getPopup(), true); Field mContentWidth = standardMenuPopup.getDeclaredField("mContentWidth"); mContentWidth.setAccessible(true); mContentWidth.setInt(helper.getPopup(), width);
|