How can i remove default search icon which appears as a hint in SearchView widget(not in actionbar)?Through styles i can change the icon but i can't find a way to remove it?
It's Worked......
ImageView searchViewIcon = (ImageView)searchView.findViewById(android.support.v7.appcompat.R.id.search_mag_icon);
ViewGroup linearLayoutSearchView =(ViewGroup) searchViewIcon.getParent();
linearLayoutSearchView.removeView(searchViewIcon);
For me it only worked this:
ImageView magImage = (ImageView) searchView.findViewById(android.support.v7.appcompat.R.id.search_mag_icon);
magImage.setVisibility(View.GONE);
magImage.setImageDrawable(null);
@sector11's almost got it, but still you need to add the line magImage.setImageDrawable(null)
because taking a look at SearchView.java
in Github,specifically the method updateViewsVisibility, you can see that it constantly gets its visibility updated
Extract from GitHub
if (mCollapsedIcon.getDrawable() == null || mIconifiedByDefault) {
iconVisibility = GONE;
} else {
iconVisibility = VISIBLE;
}
mCollapsedIcon.setVisibility(iconVisibility);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With