Android Searchview and the magnifying icon

October 01, 2015

Just a quick note about the

Normally the widget has the magnifying on the left side if expanded. So if you do something like this:

SearchView searchView =
   (SearchView) findViewById(;

We will end up with something like this:

Android Searchview standard

If we need to manipulate the magnifying icon, we need a reference to that View:

ImageView searchViewIcon =

After that just retrieve the parent ViewGroup. It is, at least today, a LinearLayout, so just remove the View and add it again to have it at the end / right side of the SearchView.

ViewGroup linearLayoutSearchView =
   (ViewGroup) searchViewIcon.getParent();

So we have something like this:

Android Searchview right

Of course, it is a standard View, so if we need to remove it altogether, just set its properties accordingly (from here):

searchViewIcon.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));