简体   繁体   English

以编程方式确定Android设备是否具有菜单按钮的方法?

[英]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及更高版本上隐藏标题栏,但这有两个原因困扰着我:

  1. I believe Android 3.0 (or a later API) will eventually support phones, which will probably have menu buttons 我相信Android 3.0(或更高版本的API)最终将支持电话,其中可能会有菜单按钮
  2. I would prefer not to hard code that SDK version (perhaps I could never hide the title bar for Android 3.0 and above, but then I run the risk of not hiding the title bar on phones) 我不想硬编码该SDK版本的代码(也许我永远都无法隐藏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.

相关问题 有没有办法以编程方式确定Android设备是否内置了拼写检查程序? - Is there any way to programmatically determine whether android device has builtin spellchecker? 以编程方式检查我的 android 设备是否已激活工作资料? - Programatically Check whether my android device has activated work profile or not? Android:如何以编程方式确定系统是否具有3G / 4G无线电? - Android : how to programatically determine whether the system has a 3G/4G radio? 如何确定Android设备是否有屏幕,即它是否是Android机顶盒? - How to determine if an Android device has a screen i.e. whether it is an Android set top box? 应使用哪个传感器来确定设备是否已使用Android Sensor向上或向下倾斜 - Which sensor should be used to determine whether device has been tilted UP or Down by using Android Sensor 如何检测android设备是否以编程方式针对所有SDK版本(所有设备)包含虚拟主页按钮还是物理主页按钮? - how to detect android device contains whether virtual home button or physical home button programatically for all SDK versions(all devices)? Android:以编程方式检测设备是否具有硬件菜单按钮 - Android: Programmatically detect if device has hardware menu button 如何以编程方式检查Android设备是否支持OTG功能 - How to check whether Android device supports OTG features programatically Chromecast SDK(Android) - 有没有办法检查播放设备上播放的媒体是否已播放完毕? - Chromecast SDK (Android) - is there a way to check whether the media playing on the cast device has finished playing? 是否可以确定是将Android设备插入计算机还是仅插入电源? - Is it possible to determine whether an Android device is plugged into a computer or just power?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM