0
    int magId = getResources().getIdentifier("android:id/search_mag_icon", null, null);
    ImageView magImage = (ImageView) mSearchView.findViewById(magId);
    magImage.setLayoutParams(new LinearLayout.LayoutParams(0, 0));
    magImage.setVisibility(View.GONE);

I'm using this above code, but it is not removing the search icon. I've set

 mSearchView.setIconified(false); 

Not understading that why it is still showing the icon.

Kishore Jethava
  • 6,666
  • 5
  • 35
  • 51
Prabh
  • 33
  • 1
  • 7
  • Check this link it already asked... [Removing default search icon from SearchView widget](http://stackoverflow.com/questions/29530742/removing-default-search-icon-from-searchview-widget) [Remove the SearchIcon as hint in the searchView](http://stackoverflow.com/questions/20323990/remove-the-searchicon-as-hint-in-the-searchview) – Android007 Oct 21 '15 at 07:02
  • @ShishirKatiyar I've checked that link already, it is not working in my case – Prabh Oct 21 '15 at 07:06

3 Answers3

5

I know this is late , but if anyone else wants to solve this problem , then

1) In style.xml add

<style name="MyToolbar" parent="AppTheme">
    <item name="searchViewStyle">@style/searchStyle</item>
</style>

If your min API level >= 21

<style name="searchStyle" parent="Widget.AppCompat.SearchView.ActionBar">
    <item name="android:queryHint">@string/search</item>
    <item name="android:searchIcon">@null</item>  
</style>

else

<style name="searchStyle" parent="Widget.AppCompat.SearchView.ActionBar">
    <item name="queryHint">@string/search</item>
    <item name="searchIcon">@null</item>
</style>

2) Finally add your style in the toolbar

<android.support.v7.widget.Toolbar
        android:id="@+id/my_toolbar"
        app:theme="@style/MyToolbar"
        />
randy
  • 765
  • 7
  • 24
3

If you use appcompat-v7 > 24, you should try this

<style name="AppTheme.SearchView" parent="Widget.AppCompat.SearchView">
    <item name="searchHintIcon">@null</item>
    <item name="searchIcon">@null</item>
    <item name="queryBackground">@android:color/transparent</item>
</style>
Ryan Huang
  • 31
  • 1
0

This worked for me :

<android.support.v7.widget.SearchView
                ...
                app:iconifiedByDefault="false"
                app:searchIcon="@null"
                />
Armin
  • 2,397
  • 2
  • 21
  • 31