Karol Jurski
Karol Jurski

Reputation: 180

Actions aren't showing on Toolbar with "ifRoom"

I have problem with actions on Toolbar in my Android app.

I have a group with some actions with app:showAsAction="ifRoom" attribute. Everything works fine if there are fewer than 4 items with ifRoom. But when I add fourth item, then all the items disappear from toolbar.

It works fine:

<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto">
<group android:id="@+id/group_paint"
    android:orderInCategory="1"
    app:showAsAction="ifRoom">
    <item android:id="@+id/action_layers"
        android:icon="@drawable/ic_layers_white_24dp"
        android:title="@string/action_layers"
        android:orderInCategory="3"
        app:showAsAction="ifRoom"/>
    <item android:id="@+id/action_tool"
        android:icon="@drawable/ic_properties_white_24dp"
        android:title="@string/action_tool"
        android:orderInCategory="4"
        app:showAsAction="ifRoom" />
    <item android:id="@+id/action_action1"
        android:icon="@drawable/ic_action1_white_24dp"
        android:title="@string/action_1"
        android:orderInCategory="7"
        app:showAsAction="ifRoom" />

    <item
        android:id="@+id/action_settings"
        android:icon="@drawable/ic_settings_white_24dp"
        android:title="@string/action_settings"
        android:orderInCategory="7"
        app:showAsAction="never" />
</group>
</menu>

It works fine

Unexpected result:

<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto">
<group android:id="@+id/group_paint"
    android:orderInCategory="1"
    app:showAsAction="ifRoom">
    <item android:id="@+id/action_layers"
        android:icon="@drawable/ic_layers_white_24dp"
        android:title="@string/action_layers"
        android:orderInCategory="3"
        app:showAsAction="ifRoom"/>
    <item android:id="@+id/action_tool"
        android:icon="@drawable/ic_properties_white_24dp"
        android:title="@string/action_tool"
        android:orderInCategory="4"
        app:showAsAction="ifRoom" />
    <item android:id="@+id/action_action1"
        android:icon="@drawable/ic_action1_white_24dp"
        android:title="@string/action_1"
        android:orderInCategory="7"
        app:showAsAction="ifRoom" />
    <item android:id="@+id/action_action2"
        android:icon="@drawable/ic_action2_white_24dp"
        android:title="@string/action_2"
        android:orderInCategory="8"
        app:showAsAction="ifRoom" />

    <item
        android:id="@+id/action_settings"
        android:icon="@drawable/ic_settings_white_24dp"
        android:title="@string/action_settings"
        android:orderInCategory="7"
        app:showAsAction="never" />
</group>
</menu>

Unexpected result

What I would like to see is: three actions on toolbar and the fourth in the overflow menu.

Upvotes: 0

Views: 129

Answers (1)

CommonsWare
CommonsWare

Reputation: 1007286

You are using the <group> element to treat the items as a group. If you do not want to treat the items as a group (e.g., you want them to appear in the action bar individually based upon available space), get rid of the <group> element.

Upvotes: 2

Related Questions