禁用菜单按钮? [英] Disable menu button?

查看:77
本文介绍了禁用菜单按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有,我想从弹出如果单击屏幕上的一个按钮来禁用它的自定义菜单选项。

I have a custom menu options that I want to disable it from popping up if a button on screen is clicked..

我想用这个code,但它不工作:

I thought of using this code but it doesnt work:

@Override
 public boolean onPrepareOptionsMenu (Menu menu) {
     if (Schedule)
         menu.getItem(1).setVisible(View.GONE);
     return true;
 }

有没有一种方法,以prevent做任何菜单按钮?谢谢你。

Is there a way to prevent the menu button from doing anything? Thanks.

推荐答案

根据文档:

You must return true for the menu to be displayed; if you return false it will not be shown.

所以,我猜测这将工作:

So I'm guessing this will work:

@Override
 public boolean onPrepareOptionsMenu (Menu menu) {
     .... Code .....
     return !Schedule;
 }

这是假设你想要的菜单显示,当计划等于假的。

That is assuming that you want the menu to display when Schedule is equal to false.

这篇关于禁用菜单按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆