I really like the new PopupMenu we got in 3.0, but I just can't display any icons next to the menu items in it. I'm inflating the menu from the .xml below:
<item android:id="@+id/menu_delete_product"
android:icon="@drawable/sym_action_add"
android:title="delete"
android:showAsAction="ifRoom|withText" />
<item android:id="@+id/menu_modify_product"
android:icon="@drawable/sym_action_add"
android:title="modify"
android:showAsAction="ifRoom|withText" />
<item android:id="@+id/menu_product_details"
android:icon="@drawable/sym_action_add"
android:title="details"
android:showAsAction="ifRoom|withText" />
With this code:
image.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
PopupMenu pop = new PopupMenu(getActivity(), v);
pop.getMenuInflater().inflate(R.menu.shelves_details_menu, pop.getMenu());
pop.show();
}
});
I can't get the icons to show up, am I missing something?
Some of the solutions above will work with the reflection hack,
Just sharing this: I've recently came across the same issues, but I also wanted to create a more customized thing (adding custom view in the menu) so I created the following lib.
https://github.com/shehabic/Droppy
I found a native solution for this, using
MenuPopupHelper.setForceShowIcon(true)
.Usage
Along the line of using reflection and without the need to use
MenuPopupHelper
, you can addprior to inflating the menu
The easiest way I found is that to use
MenuBuilder
andMenuPopupHelper
.menu.xml
Just add this tag inside
app:showAsAction="always"
I was able to show the icons using reflection. It may not be the most elegant solution but it works.