I'm trying to dynamically create a Popup Menu using Android's built-in PopupMenu class. No matter what I try, I'm unable to get the setIcon function to display anything. I've pared down my code to a pretty simple example:
public void showPopupMenu(View v) {
popupMenu = new PopupMenu(this, v);
popupMenu.setOnMenuItemClickListener(this);
MenuItem menuItem = popupMenu.add("Menu Item 1");
menuItem.setIcon(DrawableResource);
popupMenu.show();
}
The menu shows up with only the text of the menu item. The resolution of the drawable is 40x40. If I try the same thing from XML, the icon shows up just fine. Any help figuring out what might be wrong is appreciated.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…