title: Android ActionBar: collapsible SearchView with action button
body: <p>How to build <code>ActionBar</code> with collapsible search view with single action item visible, when search view is expanded? To be more descriptive, this is what I need: </p>
  
  <p><img src="https://i.stack.imgur.com/tzTj9.png" alt="enter image description here">
  Note that there are other menu items and <code>android:uiOptions="splitActionBarWhenNarrow"</code> is defined in <code>AndroidManifest.xml</code>.</p>
  
  <p>I tried to set up custom search item layout:</p>
  
  <blockquote>
    <p>menu.xml</p>
  </blockquote>
  
  <pre class="lang-html prettyprint-override"><code>&lt;item
      android:id="@+id/menu_search"
      android:actionLayout="@layout/actionbar_search"
      android:icon="@drawable/action_search"
      android:showAsAction="always|collapseActionView"
      android:title="@string/search" /&gt;
  </code></pre>
  
  <blockquote>
    <p>actionbar_search.xml</p>
  </blockquote>
  
  <pre class="lang-html prettyprint-override"><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:gravity="right"
      android:orientation="horizontal" &gt;
  
      &lt;com.actionbarsherlock.widget.SearchView
          android:id="@+id/search_view"
          android:layout_width="wrap_content"
          android:layout_height="match_parent"
          android:iconifiedByDefault="false"
          android:queryHint="@string/search_hint" /&gt;
  
      &lt;ImageButton
          android:id="@+id/add_item"
          android:layout_width="wrap_content"
          android:layout_height="match_parent"
          style="@style/Widget.Sherlock.ActionButton"
          android:src="@drawable/content_new"/&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>But by default search view takes all available width and button is not visible. I don't know how to force <code>SearchView</code> to fill all available space between app icon and menu item. All I found is <code>android:maxWidth</code> property, but this only allows to hardcoded dimension, and I'm looking for some more flexible solution. I tried also <code>RelativeLayout</code> with <code>android:layout_toRightOf="@id/search_view"</code> with no luck.</p>