ActionBarSherlock items not appearing in overflow

前端 未结 3 1537
情书的邮戳
情书的邮戳 2020-12-11 18:23

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.

M

相关标签:
3条回答
  • 2020-12-11 18:29

    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> 
    

    its look like:

    enter image description here

    Because if you are use

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

    and

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

    if you use like :

    <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> 
    

    then its look: one is on ActionBar & 2nd is open when you press menu button.

    enter image description here

    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.

    in Protrait:

    enter image description here

    in Landscape:

    enter image description here


    After Doing all above i ll saggest you to use below way in < 3.0 Android os:

    enter image description here

    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>
    
    0 讨论(0)
  • 2020-12-11 18:44

    ForceOverflow has been removed in ABS 4.1.2 with the creator sighting that it should never have made it in (see the changelog notes). I am pretty confident you are seeing expected behaviour; any device with a menu button running ICS+ (e.g. my Nexus S) does not display the overflow menu since there is a dedicated hardware key - the 'menu' button.

    Use the emulator configuration to remove the menu button from the emulated device and Android will know to add the overflow menu.

    0 讨论(0)
  • You are likely using an emulator that has a hardware keyboard enabled, and not software. To see actions in the overflow menu, use an emulator with sofwater controls. The screeenshots show two ways to do it.

    • Edit an existing AVD

    Edit an existing AVD.

    • Clone an existing device profile

    Clone an existing device profile .

    0 讨论(0)
提交回复
热议问题