ActionBarSherlock,动作条和本机菜单,如何进行? [英] ActionBarSherlock, ActionBar and Native menu, how to proceed?

查看:109
本文介绍了ActionBarSherlock,动作条和本机菜单,如何进行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写一个Android应用程序(SDK 8〜15)和我处理菜单。我读了很多关于它的东西去理解,但我坚持一点:

I'm writing an android application (sdk 8 to 15) and I'm dealing with the menu. I read a lot of things on it to understand, but I 'm stuck on one point :

显然,因为SDK 10,硬件菜单按钮不支持,现在我们必须使用操作栏即可。好。但是,在我的应用我想有这样的菜单:

Apparently since sdk 10, hardware menu button isn't supported, now we have to use the action bar. Ok. But in my app I want to have this kind of menu :

或者这样:

...这是不是硬件菜单按钮,但似乎是'本土行动起来吧。我能在网上找到的顶部的操作栏,与应用程序的标题和左边一个标志..这需要大量的地方。
我很失去了所有的SDK版本,我只是要整合像上面一个简单的菜单,我应该怎么处理?

... which are not hardware menu button but seems to be 'native action bar'. All I can find on the web is an action bar on the top, with the title of the app and a logo on the left.. which take a lot of place. I'm so lost with all those sdk versions and I just want to integrate a simple menu like above, how should I proceed ?

我有这在我的code,但:

I have this in my code, but :

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_fragments_slider, menu);
    return true;
}

...但没有菜单与Android 4显示为它应该是第一或第二映像中。

... but no menu appears with android 4 as it should be in the first or second image.

推荐答案

检查出的在Android API文档尤其是菜单资源:

Check out the Menu Resource in the Android API Documentation and especially:

安卓showAsAction = [ifRoom| 从不| withText| 总是|
  collapseActionView]

android:showAsAction=["ifRoom" | "never" | "withText" | "always" | "collapseActionView"]

从文档的例子XML是一个很好的资源也exactally如何布置一下:

The example XML from the documentation is a good resource also for exactally how to lay it out:

<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/item1"
          android:title="@string/item1"
          android:icon="@drawable/group_item1_icon"
          android:showAsAction="ifRoom|withText"/>
    <group android:id="@+id/group">
        <item android:id="@+id/group_item1"
              android:onClick="onGroupItemClick"
              android:title="@string/group_item1"
              android:icon="@drawable/group_item1_icon" />
        <item android:id="@+id/group_item2"
              android:onClick="onGroupItemClick"
              android:title="@string/group_item2"
              android:icon="@drawable/group_item2_icon" />
    </group>
    <item android:id="@+id/submenu"
          android:title="@string/submenu_title"
          android:showAsAction="ifRoom|withText" >
        <menu>
            <item android:id="@+id/submenu_item1"
                  android:title="@string/submenu_item1" />
        </menu>
    </item> </menu>

您接着需要添加到您的清单:

You then need to add to your Manifest:

android:uiOptions="splitActionBarWhenNarrow"

这将移动你的按钮下到谷底,留下标题中的动作条,如果你有比可以容纳画面更你的小三点|在下部动作条的右边。这只有真正工作在人像模式虽然,除非你有相当多的菜单项......或更长时间文本字符串(我认为...)

That will move your buttons down to the bottom, leave the title in the actionbar and if you have more than what can fit in the screen you get the little three dot | on the right of the lower actionbar. This only really works in Portrait mode though, unless you have quite a few menu items... or longer text strings (I think...)

这篇关于ActionBarSherlock,动作条和本机菜单,如何进行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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