Remove the SearchIcon as hint in the searchView

In my app i've used android.support.v7.widget.SearchView and to hide search icon this worked for me :

<android.support.v7.widget.SearchView
    ...
    app:iconifiedByDefault="false"
    app:searchIcon="@null"
/>

I've had trouble with this too. I combined the tutorial I found and an existing answer found here in stackoverflow.

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

Take note that searchView is a LinearLayout, so use LinearLayout.LayoutParams to avoid an exception.

I also tried this but it doesn't remove the view. I can't seem to figure why.:

magImage.setVisibility(View.GONE);

For the other views that you need to change, refer to this tutorial.


I've simply put @null to searchHintIcon attribute:

<style name="SearchViewMy" parent="Widget.AppCompat.Light.SearchView">
    <item name="searchHintIcon">@null</item>
</style>

and applied that style in my app theme

<style name="Theme.App" parent="Theme.AppCompat.Light.NoActionBar.FullScreen">
    <item name="searchViewStyle">@style/SearchViewMy</item>
</style>

Works for me.