PopupMenu菜单项显示图标:

加入头文件:

import java.lang.reflect.Field;
import com.android.internal.view.menu.MenuPopupHelper;

 

加入反射:

        try {
            Field field = mPopupMenu.getClass().getDeclaredField("mPopup");
            field.setAccessible(true);
            MenuPopupHelper mHelper = (MenuPopupHelper) field.get(mPopupMenu);
            mHelper.setForceShowIcon(true);
        } catch (IllegalAccessException | NoSuchFieldException e) {
            e.printStackTrace();
        }
        //mPopupMenu.show();

 

posted @ 2015-08-03 10:35  williamgufeng  阅读(1115)  评论(0编辑  收藏  举报