Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing default search icon from SearchView widget

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? enter image description here

like image 387
Android Developer Avatar asked Apr 09 '15 05:04

Android Developer


2 Answers

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);
like image 132
Praful Parmar Avatar answered Oct 29 '22 22:10

Praful Parmar


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);
like image 25
I.G. Pascual Avatar answered Oct 29 '22 21:10

I.G. Pascual