Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>After considering the suggestions from comments, many googling and testing succeeded in obtaining the desired effect. I'm not proud of this solution but it works, it's not too complicated and should be enough for this case.</p> <p>In resume what I did: </p> <ol> <li>Placed <code>SearchView</code> with custom "add item" button in <code>customView</code> of <code>ActionBar</code>. </li> <li>Removed <code>collapseActionView</code> and <code>android:actionLayout</code> from search item in <code>menu.xml</code></li> <li>Collapsing/expanding <code>SearchView</code> programmatically.</li> </ol> <p>Some code to better understand what I did. Maybe this can be useful for someone.</p> <blockquote> <p>menu.xml</p> </blockquote> <pre class="lang-html prettyprint-override"><code>&lt;item android:id="@+id/menu_search" android:icon="@drawable/action_search" android:showAsAction="always" android:title="@string/search" /&gt; // ... other menu items </code></pre> <blockquote> <p>actionbar_search.xml</p> </blockquote> <pre class="lang-html prettyprint-override"><code>&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" android:visibility="invisible" /&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" android:title="@string/add_item" /&gt; &lt;/LinearLayout&gt; </code></pre> <blockquote> <p>MainActivity.java</p> </blockquote> <pre class="lang-android prettyprint-override"><code>@Override public void onCreate(Bundle savedInstanceState) { // ... actionBar.setCustomView(R.layout.actionbar_search); actionBarCustomView = ab.getCustomView(); searchView = ((SearchView) actionBarCustomView.findViewById(R.id.search_view)); searchView.setOnCloseListener(new SearchView.OnCloseListener() { @Override public boolean onClose() { searchView.setVisibility(View.INVISIBLE); return false; } }); } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { // ... case R.id.menu_search: if (searchView.getVisibility() == View.VISIBLE) { searchView.setIconified(true); searchView.setVisibility(View.INVISIBLE); } else { searchView.setMaxWidth(abCustomView.getWidth() - addButton.getWidth()); searchView.setVisibility(View.VISIBLE); searchView.setIconified(false); } break; // ... } return true; } @Override public void onBackPressed() { if (searchView.getVisibility() == View.VISIBLE) { searchView.setIconified(true); searchView.setVisibility(View.INVISIBLE); return; } // ... } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload