The Android SearchView, which allows you to display a search UI embedded inside the ActionBar at the top of your activity, can sometimes display a magnifying glass icon outside and to the left of the EditText like this:
![]()
and other times display the magnifying glass icon inside the EditText like this, much more like the search dialog:
![]()
Moving the icon from one location to the other isn't possible by updating style or theme configuration. Trying to override the android:searchViewTextField attribute in a custom theme results in a No resource found that matches the given name: attr 'android:searchViewTextField' error.
It's possible to hide or remove the magnifying glass (and other) icons by traversing the children of the SearchView like this:
private static void hideSearchIcon(View view)
{
if (view instanceof ViewGroup)
{
ViewGroup group = (ViewGroup) view;
for (int i = 0; i < group.getChildCount(); ++i)
{
hideSearchIcon(group.getChildAt(i));
}
}
else if (view instanceof ImageView)
{
view.setVisibility(View.GONE);
}
}
It turns out that isn't a difference between the styling or themes between Honeycomb, Ice Cream Sandwich, and Jelly Bean, but is instead controlled by calling setIconifiedByDefault(boolean)
So to move the magnifying glass icon outside the search text field, call:
yourSearchView.setIconifiedByDefault(false)
Conversely, to put the icon inside the search text field, don't call setIconifiedByDefault(boolean)

But...
But what if you want the SearchView to always show expanded, but don't want the look of setIconifiedByDefault(false)?