简体   繁体   English

Android:删除某些类的Sherlock Action Bar项目

[英]Android: removing Sherlock Action Bar items for some classes

I'm having Sherlock Action Bar to show several icons in the Action Bar, like sharing, info, etc. 我有Sherlock Action Bar在Action Bar中显示几个图标,比如分享,信息等。

The thing is that I want to delete, for certain activities/fragments one of the buttons (sharing), but I can't do it. 问题是我想删除某些活动/片段中的一个按钮(共享),但我不能这样做。

My activity (StartActivity) extends from InfoActivity, which is the one that implements the onCreateOptionsMenu . 我的活动(StartActivity)从InfoActivity扩展而来,InfoActivity是实现onCreateOptionsMenu

I tried to override the onCreateOptionsMenu method and do a clear() but it doesn't work: 我试图覆盖onCreateOptionsMenu方法并执行clear()但它不起作用:

@Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        super.onCreateOptionsMenu(menu, inflater);
    }

Any ideas on how to do this? 关于如何做到这一点的任何想法?

Thanks a lot in advance. 非常感谢提前。

Find the menu item in question and disable or hide it. 找到有问题的菜单项并禁用或隐藏它。 Something like this in onCreateOptionsMenu() or onPrepareOptionsMenu() if you want to make it dynamic: onCreateOptionsMenu()onPrepareOptionsMenu()有这样的东西,如果你想让它变得动态:

menu.findItem(R.id.menu_share).setVisible(false);

What I did in the end, was creating different classes: one with the Sharing button in the menu as a button, and one without, and just making the proper activity extend from the appropriate class. 我最后做的是创建不同的类:一个用菜单中的“共享”按钮作为按钮,一个没有,只是从适当的类扩展适当的活动。

For example, StartActivity, I don't want it to have sharing capabilities, so I made it extend from an Activity without the sharing button. 例如,StartActivity,我不希望它具有共享功能,因此我将其从没有共享按钮的Activity扩展。

Thanks @NikolayElenkov for your help! 谢谢@NikolayElenkov的帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM