If there is space in the action bar because it does not show the icons that have showAsAction="ifRoom"?

1

hello I have a menu in the action bar that is as follows:

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

    <item
        android:id="@+id/menu_search"
        android:title="Buscar"
        appcompat:actionViewClass="android.support.v7.widget.SearchView"
        appcompat:showAsAction="always" />

    <item
        android:id="@+id/favorita"
        android:title="Favorito"
        android:icon="@drawable/ic_no_favorito"
        appcompat:showAsAction="always" />

    <item
        android:id="@+id/nota"
        android:title="Nota"
        android:icon="@drawable/ic_mode_comment_white_18dp"
        appcompat:showAsAction="always" />

    <item
        android:id="@+id/editar"
        android:title="Editar"
        android:icon="@drawable/ic_action_edit_white"
        appcompat:showAsAction="ifRoom" />

    <item
        android:id="@+id/enviar"
        android:title="Enviar"
        android:icon="@drawable/ic_share_white_18dp"
        appcompat:showAsAction="ifRoom" />

    <item
        android:id="@+id/donde_estoy"
        android:icon="@drawable/ic_place_white_18dp"
        android:title="¿Dónde estoy?"
        appcompat:showAsAction="ifRoom" />



</menu>

but then when I have the horizontal phone does not show the icons that have the property showAsAction="ifRoom" ..... look at the photo: see how there is space and even then there are three hidden menus ...

    
asked by Felix A Marrero Pentón 06.04.2017 в 20:07
source

2 answers

2

There are several elements that you have marked "ifRoom" in addition to the "always", remember that if there is no space for all marked as "ifRoom" will not show, in this case you also have a title that does not have text but that has a space which you should contemplate.

  

ifRoom : Just place this item in the application bar if there   space for it. If there is no space for all the marked items   as "ifRoom", the elements with the lowest values orderInCategory   are shown as actions and the remaining elements are shown in the   Overflow menu.

    
answered by 06.04.2017 в 20:43
0

you can use the setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS) function on each item of the menu that you want to force its visibility.

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_top);
setSupportActionBar(toolbar);

Menu menuItems= toolbar.getMenu();
menuItems.findItem(R.id.action_share).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
    
answered by 09.04.2017 в 21:50