gpt4 book ai didi

java - 使用混淆器时不显示自定义弹出菜单图标

转载 作者:行者123 更新时间:2023-11-30 01:15:05 24 4
gpt4 key购买 nike

我已经为我的一个 Android 应用程序实现了带有图标的自定义弹出菜单。这里我设置图标也应用了setForceShowIcon。下面是代码

 final PopupMenu popupMenu = new PopupMenu(mContext, shareFeed);
popupMenu.inflate(R.menu.custom_share_menu);
Object menuHelper;
Class[] argTypes;
Field fMenuHelper = null;
try {
fMenuHelper = PopupMenu.class.getDeclaredField("mPopup");
fMenuHelper.setAccessible(true);
menuHelper = fMenuHelper.get(popupMenu);
argTypes = new Class[]{boolean.class};
menuHelper.getClass().getDeclaredMethod("setForceShowIcon", argTypes).invoke(menuHelper, true);
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
final String des = map.get("title") + "\n" + map.get("description");
final String message = Html.fromHtml(des).toString() + "\n" + mContext.getResources().getString(R.string.app_url);
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
switch (menuItem.getItemId()) {
case R.id.whatsapp:
if (PerformCommonOps.internetConnection(mContext))
PerformCommonOps.shareFeedsOnWhatsapp(mContext, message);
else
Snackbar.make(coordinatorLayout, "Please ensure you have a working internet connection", Snackbar.LENGTH_SHORT).show();
return true;
case R.id.facebook:
if (PerformCommonOps.internetConnection(mContext))
PerformCommonOps.shareToFacebbok(mContext, mContext.getResources().getString(R.string.app_url), view, (Activity) mContext);
else
Snackbar.make(coordinatorLayout, "Please ensure you have a working internet connection", Snackbar.LENGTH_SHORT).show();
return true;
case R.id.text:
if (PerformCommonOps.internetConnection(mContext))
PerformCommonOps.sendText(mContext, message);
else
Snackbar.make(coordinatorLayout, "Please ensure you have a working internet connection", Snackbar.LENGTH_SHORT).show();
return true;
case R.id.googleplus:
if (PerformCommonOps.internetConnection(mContext))
PerformCommonOps.shareOnGooglePlus(mContext, Html.fromHtml(des).toString(), mContext.getResources().getString(R.string.app_url), view);
else
Snackbar.make(coordinatorLayout, "Please ensure you have a working internet connection", Snackbar.LENGTH_SHORT).show();
return true;
default:
common();
return true;
}

}
});
popupMenu.show();

当我在 Debug模式下运行应用程序时显示图标,但在使用Proguard Release模式时图标不显示显示。这是我的 setForceShowIcon

proguard 配置
######################################
####### POPUpMenu configurations######
######################################
-keepclassmembernames class android.support.v7.widget.PopupMenu { private android.support.v7.internal.view.menu.MenuPopupHelper mPopup; }
-keepclassmembernames class android.support.v7.internal.view.menu.MenuPopupHelper { public void setForceShowIcon(boolean); }

请让我知道哪里和哪里做错了。 TIA

最佳答案

由于 setForceShowIconandroid.support.v7.view.menu.MenuPopupHelper 的成员,一般来说,我将这些行添加到我的 proguard-rules 中,它非常有效嗯:

-keep class * extends android.support.v7.** { *; }
-keepclassmembernames class * extends android.support.v7.** { *; }

关于java - 使用混淆器时不显示自定义弹出菜单图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37966361/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com