You can use reflection to achieve this
java code
Context contextWrapper = new ContextThemeWrapper(MainActivity.this, R.style.PopupStyle);
PopupMenu popup = new PopupMenu(contextWrapper,v);
/* The below code in try catch is responsible to display icons*/
try {
Field[] fields = popup.getClass().getDeclaredFields();
for (Field field : fields) {
if ("mPopup".equals(field.getName())) {
field.setAccessible(true);
Object menuPopupHelper = field.get(popup);
Class<?> classPopupHelper = Class.forName(menuPopupHelper.getClass().getName());
Method setForceIcons = classPopupHelper.getMethod("setForceShowIcon", boolean.class);
setForceIcons.invoke(menuPopupHelper, true);
break;
}
}
} catch (Exception e) {
e.printStackTrace();
}
popup.getMenuInflater().inflate(R.menu.pop_up, popup.getMenu());
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
Toast.makeText(MainActivity.this,
"Clicked popup menu item " + item.getTitle(),
Toast.LENGTH_SHORT).show();
return true;
}
});
popup.show();
pop_up.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/red"
android:icon="@android:drawable/presence_online"
android:title="Red" />
<item android:id="@+id/white"
android:icon="@android:drawable/presence_online"
android:title="White" />
<item android:id="@+id/blue"
android:icon="@android:drawable/presence_online"
android:title="Blue" />
</menu>
and if you want to change the menu style
in styles.xml
<style name="PopupStyle" parent="Widget.AppCompat.PopupMenu">
<item name="android:textColorPrimary">@color/colorAccent</item>
</style>
or if you want to create custom layout check link1, link2