How do I programmatically add an image to Android PopupMenu ()?
I would like to add thumbnails to each item in my popup menu. I can dynamically create my menu and add text elements, how can I add images, you can give an example or direct me to some resources
I want to do it without using xml like I did below.
Sample code ...
popupMenu = new PopupMenu(VideoPlayer.this, v);
if(bitRates != null){
int menuItem = 0;
popupMenu.getMenu().add(0,menuItem, 0,"Hide menu");
for(int i=1;i<bitRates.size();i++){
menuItem = i;
popupMenu.getMenu().add(0,menuItem, 0,qualityList.get(i)+" : "+bitRates.get(i));
Log.i("ITEM",qualityList.get(i)+" : "+bitRates.get(i));
}
popupMenu.getMenu().add(0,menuItem++, 0,"Back to home");
}
popupMenu.show();
thank
+3
source to share