处理新版本 Android(3.x 及更高版本)中缺失的 MENU 按钮

发布于 2024-12-25 09:22:51 字数 819 浏览 1 评论 0原文

我是 Android <3.0 中使用的菜单按钮的粉丝,因为它对我的游戏应用程序非常有用 - 它允许我采用重要但与游戏无关的功能(保存游戏、参考信息链接)并将其放置在某个位置它没有使主游戏界面变得混乱,但仍然很容易访问(选项菜单)。

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

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

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

this.openOptionsMenu();

,一切都在 ICS 中恢复正常工作。

然而,这在 Honeycomb 上不起作用。如果 ActionBar 不可见,调用 openOptionsMenu 绝对不会执行任何操作。

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

  • 我想我总是可以回到使用 TargetSDK

    11(从而强制 ActionBar 出现在平板电脑上),但据我所知,这只是将问题推到未来,我不想这样做。

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

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

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).

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.

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.

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();

And everything is back to working perfectly in ICS.

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?

  • 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

无人接听 2025-01-01 09:22:51

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

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

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

有多种解决方法,但没有一个是容易的。

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

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

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

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

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

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.

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.

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.

EDIT: 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.

迷你仙 2025-01-01 09:22:51

但是,ICS 使这成为一个严重的问题,因为 MENU 按钮显然不会回来。

更准确地说,是否有屏幕外按钮(例如菜单)取决于设备制造商。引用Android 4.0的兼容性定义文档:

主页、菜单和返回功能对于 Android 导航范例至关重要。设备实现
必须使用户在运行应用程序时始终可以使用这些功能。这些功能可能是
通过专用物理按钮(例如机械或电容式触摸按钮)实现,或者可以
使用专用软件按键、手势、触摸屏等实现。

因此,您不能指望有一个屏幕外菜单按钮,尽管很可能有一个。

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

编写您自己的“菜单”作为游戏用户界面的一部分。我不希望有一款游戏认为需要全屏才能使用选项菜单——事实上,我不记得曾经见过这样的游戏(不过,不可否认,我不是一个资深的游戏玩家) 。我玩过的所有游戏在按菜单键时都不起作用。相反,任何可能被视为“菜单”的内容都直接在游戏 UI 中实现(例如,通向屏幕的按钮,以游戏 UI 的外观和感觉进行格式化,提供要做的事情的选择)。

完全放弃选项菜单,并改为仅使用上下文菜单?

这将是可怕的,因为用户将不知道长按哪里来调出菜单。

However, ICS makes this a serious issue, since the MENU button is obviously not coming back.

More accurately, it is up to device manufacturers whether to have off-screen buttons or not for things like MENU. Quoting the Compatibility Definition Document for Android 4.0:

The Home, Menu and Back functions are essential to the Android navigation paradigm. Device implementations
MUST make these functions available to the user at all times when running applications. These functions MAY be
implemented via dedicated physical buttons (such as mechanical or capacitive touch buttons), or MAY be
implemented using dedicated software keys, gestures, touch panel, etc.

So, you cannot count on there being an off-screen MENU button, though there may well be one.

Any thoughts on how to deal with this?

Write your own "menu" as part of your game UI. I would not expect a game that thinks it needs the full screen to use the options menu -- in fact, I can't remember ever seeing a game that did that (though, admittedly, I am not a big-time game player). All the games that I have played do nothing on a MENU press. Rather, anything that might be considered a "menu" is implemented directly in the game UI (e.g., a button that leads to a screen, formatted in the game UI's look-and-feel, that offers choices for things to do).

Drop the Options Menu entirely, and go over to only using Context Menus?

That would be awful, as users will not know where to long-press to bring up the menu.

清欢 2025-01-01 09:22:51

为了将最后一个钉子放入众所周知的菜单按钮棺材中,谷歌做出了最后的告别:

http://android-developers.blogspot.com/2012/01/say-goodbye-to-menu-button.html

And just to put the last spike in the proverbial coffin of the menu button, Google weighs in with a final goodbye:

http://android-developers.blogspot.com/2012/01/say-goodbye-to-menu-button.html

烟─花易冷 2025-01-01 09:22:51

迈克尔,我遇到了完全相同的情况,并通过使用自定义对话框实现我的选项菜单来解决它。它在 ICS 上看起来比底部的旧选项菜单更好。它的配置是这样的

minSdkVersion = 8
目标SdkVersion = 14
SDK 构建版本 8(在 Eclipse 设置中。可以设置为 14,但我喜欢它提供的类型安全性)

API < 的用户10 使用硬菜单按钮并查看标准选项菜单。
API >= 10 的用户会在应用程序中看到一个三点图标(溢出菜单),单击时会获取我的自定义对话框菜单。他们还在“设置”等中看到新的 ICS 外观。

“菜单”按钮似乎没有回来,我想打破传统障碍,尽管只有 <1% 的用户使用 ICS。

Michael, I was in exactly the same situation and solved it by implementing my option menu using a custom dialog. It looks better on ICS than the legacy option menu at the bottom. It is configured like this

minSdkVersion = 8
targetSdkVersion = 14
SDK build version 8 (in eclipse settings.could set to 14 but I like the type safety it provides)

Users with API < 10 use the hard menu button and see the standard option menu.
Users with API >= 10 see a three dot icon (overflow menu) in the app and when click get my custom dialog menu. They also see the new ICS look in Settings, etc.

It does not seem that the Menu button is coming back and I wanted to break the legacy barrier even though only <1% of my users use ICS.

够运 2025-01-01 09:22:51

回应最近的博客文章,他们似乎希望开发人员开始使用操作栏而不是菜单,但如果想要支持 API => ,这会变得很痛苦。 3.0和API< 3.0。因此,要么创建一个与 API 兼容的自定义 Action Bar < 3.0(您可以在 SDK 中找到示例),或者...我上周正在尝试这个:

我还遇到了一个问题,菜单按钮没有出现在我的 ICS 平板电脑上,我相信我已将 targetSdk 设置为 11我想实现一个 ActionBar 的时间。然后我将minSdk设置为3,targetSdk设置为4。ActionBar和菜单溢出按钮都出现了。所以这就是现在的解决方法(至少对于我正在从事的项目而言)。

Responding to that recent blog post, they seem to want developers to start using Action Bars over Menus, but this becomes a pain if wanting to support API => 3.0 and API < 3.0. So either create a custom Action Bar that is compatible with API < 3.0 (you can find examples in the SDK), or... I was experimenting with this last week:

I also had an issue where the menu button did not appear on my ICS tablet, I believe I had targetSdk set to 11 at the time as I wanted to implement an ActionBar. Then I set minSdk to 3, and targetSdk to 4. Both the ActionBar and the menu overflow button appeared. So this is the workaround right now (at least for the project I'm working on).

人间不值得 2025-01-01 09:22:51

我为 3.x 版本添加了特殊逻辑。
仅对于这些版本我使用操作栏。

            if (Build.VERSION.SDK_INT == Build.VERSION_CODES.HONEYCOMB
             || Build.VERSION.SDK_INT == Build.VERSION_CODES.HONEYCOMB_MR1
             || Build.VERSION.SDK_INT == Build.VERSION_CODES.HONEYCOMB_MR2) {
                requestWindowFeature(Window.FEATURE_ACTION_BAR);        
            }
            else{
//              hide the status bar, do not use action bar         
                requestWindowFeature(Window.FEATURE_NO_TITLE);    
                getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);               
            }

对于所有其他版本,我显示自己的菜单按钮并以全屏模式运行我的游戏。
当按下菜单按钮时,我使用以下代码行,其中“act”是当前活动。

act.openOptionsMenu();

作为菜单 xml 的一部分,请确保有这样一行来设置“showAsAction”

showAsAction="ifRoom"

I added a special logic for 3.x releases.
Only for these releases I use the action bar.

            if (Build.VERSION.SDK_INT == Build.VERSION_CODES.HONEYCOMB
             || Build.VERSION.SDK_INT == Build.VERSION_CODES.HONEYCOMB_MR1
             || Build.VERSION.SDK_INT == Build.VERSION_CODES.HONEYCOMB_MR2) {
                requestWindowFeature(Window.FEATURE_ACTION_BAR);        
            }
            else{
//              hide the status bar, do not use action bar         
                requestWindowFeature(Window.FEATURE_NO_TITLE);    
                getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);               
            }

For all other releases I display my own menu button and run my game in fullscreen mode.
When pressing my menu button, I use the following code line, where "act" is the current activity.

act.openOptionsMenu();

As part of your menu xml, make sure to have a line like this to set "showAsAction"

showAsAction="ifRoom"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文