简体   繁体   English

如何在软件键盘上添加菜单按钮

[英]How to add menu button on the software keyboard

not sure if the title is correct, but here's what I need. 不确定标题是否正确,但这就是我需要的。 I have Xperia V, and as I guess, like most new phones, it does not have any buttons on the phone, but instead they appear on the display itself, the Home, Back and something like Tasks, dont know... What I want to know is how do I add a menu button next to these 3 buttons in an app, you know when there is a title bar in the app it appears up there, but with no title bar this menu button (its 3 dots) must be next to the other software buttons. 我有Xperia V,而且我猜,就像大多数新手机一样,手机上没有任何按钮,但它们出现在显示器本身,Home,Back和Tasks之类的东西,不知道......我是什么我想知道如何在应用程序中的这3个按钮旁边添加一个菜单按钮,你知道当应用程序中有一个标题栏出现在那里时,但没有标题栏这个菜单按钮(它的3个点)必须紧挨着其他软件按钮。 How can I do it in my app? 我怎么能在我的应用程序中执行此操作?

For starters, you will get a lot of people telling you here that this is a bad idea, and an old UI pattern. 对于初学者来说,你会得到很多人在这里告诉你这是一个坏主意和一个旧的UI模式。 They are right... 他们是对的...

Here is my answer on a related question - and also lots of other opinions on the topic (some quite amusing): 以下是我对相关问题的回答 - 以及关于该主题的许多其他意见(一些非常有趣):

I particularly enjoy Compatibility Menu of Shame reference from @nicopico's answer . 我特别喜欢来自@ nicopico的答案 的羞耻参考兼容菜单

Please consider if you really want it - only use in extreme cases, like maybe your client is insisting. 请考虑一下你是否真的想要它 - 只能在极端情况下使用,比如你的客户可能会坚持。 Otherwise avoid this pattern. 否则避免这种模式。


You can set your build target to a version before ICS (ie up to and including API 13 / HoneyComb 3.2). 您可以将build target设置为ICS之前的版本(即,包括API 13 / HoneyComb 3.2)。

<uses-sdk
    android:minSdkVersion="7"
    android:targetSdkVersion="13" />

That will get the system to use a compatibility mode setting that inserts an overflow icon into your phone's bottom button bar - this should provide the functionality you are after. 这将使系统使用兼容模式设置,将overflow图标插入手机的底部按钮栏 - 这应该提供您所需的功能。 Pressing this button will have the same response as pressing a "menu" button on the Samsung Galaxy S2 for example. 按下此按钮的响应与按Samsung Galaxy S2上的“菜单”按钮的响应相同。


Here you can see the compatibility "options" button, and the menu that has been shown when it was pressed: 在这里,您可以看到兼容性“选项”按钮,以及按下时显示的菜单:

Galaxy Nexus上的ICS兼容性选项按钮


Note: 注意:

As other commentators mention, you should consider the better choice of the ActionBar pattern. 正如其他评论员所提到的,你应该考虑更好地选择ActionBar模式。 If you want backwards compatibility, then I recommend the Action Bar Sherlock library. 如果你想向后兼容,那么我推荐Action Bar Sherlock库。

But if you are looking for a quick fix, or the client can't afford a big refactor to move to the Action Bar pattern, then this is the way to do it. 但是,如果您正在寻找快速修复,或者客户端无法承受大型重构转移到Action Bar模式,那么这就是实现它的方法。

In your AndroidManifest you have to set the targetSdkVersion to 13 or earlier : <uses-sdk android:targetSdkVersion="13" /> .This will force ICS to run application in compatibility mode and to show 3 dots in system bar for overflow menu. 在你的AndroidManifest中你必须将targetSdkVersion设置为13或更早: <uses-sdk android:targetSdkVersion="13" /> 。这将强制ICS在兼容模式下运行应用程序,并在系统栏中显示溢出菜单的3个点。 But as koso and Richard Le Mesurier said this is a VERY bad idea. 但正如koso和Richard Le Mesurier所说,这是一个非常糟糕的主意。 You should use Action Bar pattern or Fly-In App Menu pattern (Slide Menu) for this purposes. 为此,您应该使用Action Bar模式或Fly-In App菜单模式(幻灯片菜单)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM