处理新版本 Android(3.x 及更高版本)中缺少的 MENU 按钮 [英] Handling the missing MENU button in new versions of Android (3.x and up)

本文介绍了处理新版本 Android(3.x 及更高版本)中缺少的 MENU 按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很喜欢 Android <3.0 中使用的菜单按钮,因为它对我的游戏应用非常有用 - 它允许我使用重要但与游戏无关的功能(保存游戏、参考信息链接)并放置它不会使主游戏界面混乱,但仍然可以轻松访问(选项菜单).

I'm a fan of the menu button as used in Android <3.0, as it was very useful for my game apps - it allowed me to take important but gameplay irrelevant functionality (saving game, reference info links) and place it somewhere where it did not clutter up the main game interface, but was still easily accessible (the options menu).

这种按键的使用在 3.0 中成为一个问题,因为它删除了 MENU 按钮并用操作栏代替.Action栏真的不适合喜欢全屏运行的游戏,真的很痛苦.没有操作栏 - 无法访问选项菜单.但是,我可以暂时忽略它,因为我在平板电脑上没有那么多用户,也没有时间对此进行测试.

This use of keys became a problem with 3.0, because it removed the MENU button and substituted it with the Action Bar. The Action bar is really not suitable for a game which likes to run full-screen, so that was a real pain. No action bar - no access to the options menu. However, I could sort of ignore it for a while, since I didn't have that many users on tablets and lacked the time to test this.

然而,ICS 使这成为一个严重的问题,因为 MENU 按钮显然不会回来.现在,我不仅要在平板电脑上处理这些问题,还要在手机上处理这些问题.

However, ICS makes this a serious issue, since the MENU button is obviously not coming back. Now I don't only have to deal with this problems on tablets, but on phones as well.

我对这个问题的最初解决方案是简单地在我的 GUI 中放置一个软按钮来替换硬 MENU 按钮

My initial solution to this problem has been to simply place a soft button in my GUI to replace the hard MENU button

this.openOptionsMenu();

一切都可以在 ICS 中完美运行.

And everything is back to working perfectly in ICS.

但是,这不适用于 Honeycomb.如果 ActionBar 不可见,则调用 openOptionsMenu 绝对没有任何作用.

However, this does not work on Honeycomb. Calling openOptionsMenu does absolutely nothing if you do not have the ActionBar visible.

关于如何处理这个问题有什么想法吗?

Any thoughts on how to deal with this?

  • 我想我总是可以回到使用 TargetSDK <11(从而迫使 ActionBar 出现在平板电脑上),但据我所知,这只是将问题推到了未来,我不想这样做.

  • I suppose I could always go back to using TargetSDK < 11 (thereby forcing the ActionBar to appear on tablets), but as far as I can see this is merely pushing the problem into the future, which I would prefer not to do.

完全放弃选项菜单,转而只使用上下文菜单?[澄清:我的意思是,不是打开选项菜单 - 我只使用上下文菜单,因为 - 至少现在 - 这些适用于所有设备].

Drop the Options Menu entirely, and go over to only using Context Menus? [Clarification: By this I mean that instead of opening an options menu - I only use context menus since - at least for now - these work on all devices].

有兴趣了解其他对整个选项菜单/操作栏混乱有类似问题的人决定做什么.

Interested in hearing what others who have had similar issues with the whole Options Menu/ActionBar mess decided to do.

推荐答案

让我分享另一个场景,即使菜单按钮不是游戏,它也变得至关重要.

Let me share another scenario where Menu Button becomes critical even though it is not a game.

我让应用程序实现了自己的工具栏,其行为在某种程度上类似于 ActionBar.好吧,我做到了,因为我的应用程序是使用 1.5 sdk 发布的.当时还没有这个概念.为了适应我的工具栏,我隐藏了默认的标题栏.但有些操作是通过菜单功能完成的.

I have app implement its own tool bars which behave to some extent like ActionBar. Well I did that coz my app was released with 1.5 sdk. At that time there is no such concept. And to accomodate for my toolbars i hide the default title bar. But some of the actions are done through Menu functionality.

现在因为在 Galaxy Nexus 中,如果您不使用 ActionBar 就没有菜单按钮,这对我很不利,因为我的应用程序仍然支持 1.5.

Now since in Galaxy Nexus there is no Menu button if you are not using ActionBar and that is hurting me because my app still supports 1.5.

嗯,有各种变通方法,但没有一个是容易的.

Well there are various work arounds, but none is easy.

也就是说,我想出的唯一解决方法是在我的工具栏上为用户提供所有选项,因此根本不需要菜单.我可以这样做,因为我只有两个不属于工具栏的操作.

That said, the only work around I come up with is to give user all options on my toolbar, so there is no need for Menu at all. I can do this because i only have two actions which are not part of the toolbar.

在您的情况下,按钮上的上下文菜单在游戏中并不是一个糟糕的解决方案,因为与在每个项目都是不同上下文的列表项上的上下文菜单相比,游戏将只有一个上下文来运行.

In your situation, context menu on a button is not a bad soln in a game as game will have only one context in which it is running as compared to having context menu on list items where every item is a different context.

顺便说一句,如果 openOptionsMenu 在 ICS 上工作并且你可以在一段时间后放弃 HoneyComb(即使现在用户群太低)然后尝试给两个菜单 基于版本.

BTW if openOptionsMenu works on ICS and you can ditch HoneyComb after a while (even now the userbase is too low) then try giving both menus based on the version.

还有另一种方法可以在下面的导航栏中获得 MENU s/w 按钮.只需将 targetSdkVersion 设置为小于 11.有关更多详细信息,请pls阅读整个解决方案.

Well there is another way also to get the MENU s/w button in the below navigation bar. Just set the targetSdkVersion to less than 11. For more details pls read the whole soln.

这篇关于处理新版本 Android(3.x 及更高版本)中缺少的 MENU 按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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