[英]way to programatically determine whether an Android device has a menu button?
I need to compensate for the lack of a physical (or even a "soft") menu button on Android 3 tablets. 我需要弥补Android 3平板电脑上缺少物理(甚至是“软”)菜单按钮的不足。 The app I'm working on generally hides the title bar for its activities, but I can't do that if I want the action bar to appear on a tablet.
我正在使用的应用通常会隐藏其活动的标题栏,但是如果我希望操作栏出现在平板电脑上,则无法这样做。 Is there something in the API that I can use to determine whether a device has a menu button?
API中是否可以用来确定设备是否具有菜单按钮?
If I can't find such a function, the only thing I can think of to do is to never hide the title bar on Android 3.0 and later, but that bothers me for two reasons: 如果找不到这样的功能,我唯一想做的就是永远不要在Android 3.0及更高版本上隐藏标题栏,但这有两个原因困扰着我:
LeffelMania has the right idea, but there is a caveat: If you target SDK 11 (3.0) and use a no-title-bar theme or override with a custom title of some sort, you will be just plain menu-less, because on Honeycomb devices with the target set to 11 the options-menu lives in the title bar itself instead of a fake menu button in the bottom status bar. LeffelMania有一个正确的想法,但有一个警告:如果您以SDK 11(3.0)为目标并使用无标题栏主题或使用某种自定义标题进行覆盖,则您将获得无菜单显示,因为将目标设置为11的Honeycomb设备,选项菜单位于标题栏中,而不是底部状态栏中的伪菜单按钮。 So be careful there!
所以要小心! (You can work around this by setting a lower target, or targeting style resources to v11 to use a one of the Holo themes with a titlebar in that case).
(您可以通过设置较低的目标或将样式资源定位到v11以在这种情况下使用带有标题栏的Holo主题之一来解决此问题)。
DEPRECATED: This answer is no longer accurate, given changes to the Android framework and design guidelines. 已弃用:鉴于对Android框架和设计准则的更改,此答案不再准确。
Android phones are guaranteed to have a Menu button. 保证Android手机具有“菜单”按钮。 All phones pre-Honeycomb have Menu buttons, and Honeycomb features an ever-present software button.
蜂窝电话之前的所有电话都具有菜单按钮,而蜂窝电话则具有一个始终存在的软件按钮。 If you use the proper callbacks that tie into the Menu button (onCreateOptionsMenu(), onOptionsItemSelected(), etc) you will be safe to receive those callbacks on any device running Android.
如果您使用与菜单按钮相关的正确回调(onCreateOptionsMenu(),onOptionsItemSelected()等),则可以安全地在运行Android的任何设备上接收这些回调。
从API级别14开始, ViewConfiguration.hasPermanentMenuKey()可用于指示是否存在永久菜单键。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.