如何禁用菜单按钮和操作栏仍然存在 [英] How to disable menu button and the action bar still remains there

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

问题描述

我在禁用菜单按钮有问题,我不想要的菜单按钮,可以启用,停用通过返回上prepareOptionsMenu 的功能,但它隐藏了所有行动项目在我的行动吧,这样如何禁用不影响我的动作条菜单按钮?

I have a problem in disabling menu button , I dont want the menu button to be enable , I disable is by returning false in onPrepareOptionsMenu function , but it hides all action items in my action bar, so How to disable menu button without affecting my actionbar?

推荐答案

硬件菜单按钮不被在prepareOptionsMenu控制()。一般来说,它是不是很好的做法,改变硬件按钮的行为,因为用户所期望的行为以一定的方式(我认为这是扩大溢出菜单)。

Hardware menu button is not controlled by onPrepareOptionsMenu(). Generally speaking, it is not good practice to change the behavior of hardware buttons because users expect it to behave a certain way (which I believe is to expand the overflow menu).

如果你绝对要禁用它,你可以听它是pssed我们的活动像这样$ P $:

If you absolutely have to disable it, you could listen for it to be pressed in our Activities like this:

public boolean dispatchKeyEvent(KeyEvent event) {
    final int keycode = event.getKeyCode();
    final int action = event.getAction();
    if (keycode == KeyEvent.KEYCODE_MENU && action == KeyEvent.ACTION_UP) {
        return true; // consume the key press
    }
    return super.dispatchKeyEvent(event);
}

这篇关于如何禁用菜单按钮和操作栏仍然存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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