Remove Search View icon from hint text

user1785900 picture user1785900 · Dec 3, 2014 · Viewed 15.8k times · Source

I am using appcompat library with a toolbar and I have implemented a search view in my app. But i want to remove the search view icon when its expanded.

here is my menu xml file:

<item
    android:id="@+id/action_search"
    android:icon="@drawable/ic_search"
    android:title="@string/action_search"
    app:actionViewClass="android.support.v7.widget.SearchView"
    app:showAsAction="ifRoom|collapseActionView"/>

and this is how I inflate the menu:

getMenuInflater().inflate(R.menu.main, menu);
SearchView searchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.action_search));
searchView.setQueryHint(getString(R.string.search_hint));
return super.onCreateOptionsMenu(menu);

this is what i want to remove:

enter image description here

Answer

Rafael picture Rafael · Sep 21, 2015

This helped me to remove Search icon

searchView.setIconified(false);

If you want searchView always expanded use just this:

searchView.onActionViewExpanded();