没有出现在溢出ActionBarSherlock项目 [英] ActionBarSherlock items not appearing in overflow

查看:117
本文介绍了没有出现在溢出ActionBarSherlock项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想restyle我的应用程序的ICS的外观和感觉与ABS。获取动作条本身是好的和简单的,但添加菜单项一直没有。

I'm trying to restyle my app to an ICS look and feel with ABS. Getting the ActionBar itself was nice and straightforward, however adding menu items has not been.

我的code是这样的:

My code looks like:

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        super.onCreateOptionsMenu(menu);
        MenuInflater inflater = getSupportMenuInflater();
        inflater.inflate(R.menu.menu, menu);
        return true;
    }

所有相应的进口产品正在使用。

All the appropriate imports are being used.

和我menu.xml文件如下:

And my menu.xml is as follows:

<?xml version="1.0" encoding="utf-8"?>
<menu
  xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:id="@+id/backup" android:title="@string/backupLabel"/>
  <item android:id="@+id/restore" android:title="@string/restoreLabel"/>
</menu>

在动作条显示,但菜单相当于一个2.1的菜单 - 从菜单键,无可用溢出只有激活。这也是真正在一个ICS模拟器 - 在那里我必须使用菜单键激活菜单

The ActionBar shows, but the menu behaves as a 2.1 menu - only activating from the menu button with no overflow available. This is also true on an ICS emulator - where I have to use the menu button to activate the menu.

如果我想补充的android:showAsAction =ifRoom,那么项目为行动项目 - 但不是在溢出,这是我想他们永远是

If I add android:showAsAction="ifRoom" then the items appear as action items - but not in the overflow, which is where I would like them to always be.

这是否是行得通?

我在想什么?

推荐答案

只需使用此code boath菜单上动作条:

just use this code boath menu are on ActionBar:

<menu xmlns:android="http://schemas.android.com/apk/res/android" >

    <item
        android:id="@+id/backup"
        android:showAsAction="ifRoom"
        android:title="backupLabel"/>
    <item
        android:id="@+id/restore"
        android:showAsAction="ifRoom"
        android:title="restoreLabel"/>
</menu> 

它的样子:

因为如果你是使用

android:showAsAction="ifRoom" : Only place this item in the Action Bar if there is room for it.

android:showAsAction="Never" : Never place this item in the Action Bar.

如果你使用这样的:

<menu xmlns:android="http://schemas.android.com/apk/res/android" >

        <item
            android:id="@+id/backup"
            android:showAsAction="ifRoom"
            android:title="backupLabel"/>
        <item
            android:id="@+id/restore"
            android:title="restoreLabel"/>
    </menu> 

那么它的样子:一个是在动作条和放大器;第二个是开放的,当你preSS菜单按钮。

注意:它做工精细与&lt; 3.0 Android操作系统,所以不要担心但是,如果你有多个菜单项(更多然后3)机器人:showAsAction =ifRoom然后告诉你取决于设备的屏幕尺寸

Note : Its working fine in < 3.0 Android OS so don't worry. But if you have multiple menu item(more then 3) with android:showAsAction="ifRoom" then it show you depend on device screen size.

在写真:

景观:

做上述所有我会saggest你下面要使用方式℃后, 3.0 Android操作系统:

code:

<menu xmlns:android="http://schemas.android.com/apk/res/android" >

    <item
        android:id="@+id/file"
        android:showAsAction="ifRoom"
        android:title="file">

        <!-- "file" submenu -->
        <menu>
            <item
                android:id="@+id/create_new"
                android:title="create_new"/>
            <item
                android:id="@+id/open"
                android:title="open"/>
        </menu>
    </item>

</menu>

这篇关于没有出现在溢出ActionBarSherlock项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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