I am doing an application where for example when i click on the image(it is a searchView)
Use "searchHintIcon" attribute in your styles for that:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="searchViewStyle">@style/AppTheme.SearchView</item>
</style>
<style name="AppTheme.SearchView" parent="Widget.AppCompat.SearchView">
<item name="searchHintIcon">@null</item>
</style>
You can replace @null with any drawable res you want
It's answer
ImageView searchViewIcon = (ImageView)searchView.findViewById(android.support.v7.appcompat.R.id.search_mag_icon);
ViewGroup linearLayoutSearchView =(ViewGroup) searchViewIcon.getParent();
linearLayoutSearchView.removeView(searchViewIcon);
Try these three lines:
android:iconifiedByDefault="false"
android:searchIcon="@null"
android:searchHintIcon="@null"
*It works only for android.widget.SearchView
If you use androidx.appcompat.widget.SearchView:
You can hide the icon using this:
val magImage = searchView.findViewById<View>(androidx.appcompat.R.id.search_mag_icon) as ImageView
magImage.layoutParams = LinearLayout.LayoutParams(0, 0)
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.
Simple solution is searchHintIcon attribute
<style name="SearchViewStyleMyApp" parent="Widget.AppCompat.SearchView">
<!-- Background for the search query section (e.g. EditText) -->
<item name="queryBackground">@android:color/white</item>
<!-- note that this is how you style your hint icon -->
<item name="searchHintIcon">@null</item>
<!-- The hint text that appears when the user has not typed anything -->
<item name="queryHint">@string/search_hint</item>
</style>