我在项目列表中创建一个带有图标的弹出菜单。我想改变图标,但它不起作用。我的代码中的任何错误都在下面?
PopupMenu popup = new PopupMenu(activity, v);
popup.getMenuInflater().inflate(R.menu.action_menu_lokasi, popup.getMenu());
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
int which= item.getItemId();
return true;
}
});
Menu menu = popup.getMenu();
MenuItem action_realisasi_mingguan = menu.findItem(R.id.action_realisasi_mingguan);
action_realisasi_mingguan.setIcon(
new IconDrawable(getActivity(), FontAwesomeIcons.fa_arrow_right)
.colorRes(R.color.colorPrimary)
);
MenuItem action_gambar_lokasi = menu.findItem(R.id.action_gambar_lokasi);
action_gambar_lokasi.setIcon(
new IconDrawable(getActivity(), FontAwesomeIcons.fa_picture_o)
.colorRes(R.color.colorPrimary)
);
// Force icons to show
try {
Field mFieldPopup=popup.getClass().getDeclaredField("mPopup");
mFieldPopup.setAccessible(true);
MenuPopupHelper mPopup = (MenuPopupHelper) mFieldPopup.get(popup);
mPopup.setForceShowIcon(true);
} catch (Exception e) {
Log.w(TAG, "error forcing menu icons to show", e);
return;
}
popup.show();
如何修复它?感谢