0

I am using Toolbar from the support AppCompat v21 library and I want to put a color as background in a Item.

I want something like this (Image link)

I can't put the background with the full height of the Toolbar

I am getting this (Image link)

My code: menu.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:xxxx="http://schemas.android.com/apk/res-auto">
    <item
        android:id="@+id/action_search"
        android:icon="@drawable/new_action_search"
        android:title="@string/buscador_hint_busqueda"
        xxxx:actionViewClass="android.support.v7.widget.SearchView"
        xxxx:showAsAction="collapseActionView|ifRoom"
        />
    <item
        android:id="@+id/action_search_filter"
        android:title="@string/buscador_filtrar"
        android:icon="@drawable/ic_filter"
        xxxx:showAsAction="ifRoom|withText" />
    <item
        android:id="@+id/action_save"
        android:title="@string/buscador_save"
        android:icon="@drawable/action_item_save_icon"
        xxxx:showAsAction="ifRoom"/>
</menu>

action_item_save_icon.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape>
            <solid android:color="@color/green_bumeran_material"></solid>
            <size
                android:height="?attr/actionBarSize"
                android:width="?attr/actionBarSize" />
        </shape>
    </item>
    <item>
        <bitmap android:src="@drawable/ic_pin_save" />
    </item>
</layer-list>

2 Answers2

0

You can use views into toolbar instead of menu, make your own layout

look to this question, he use layout instead of menus

Community
  • 1
  • 1
Kirill Shalnov
  • 2,216
  • 1
  • 19
  • 21
0

Create an xml layout with your desired look. Make sure the height="match_parent". Get a hold of your menu, then get the appropriate item with menu.getItem(int). Then on your MenuItem do menuItem.setActionView() with either an inflated layout or the resource id for that layout.

Andrew Orobator
  • 7,978
  • 3
  • 36
  • 36