How to change SearchView default icon? How to change SearchView default icon? android android

How to change SearchView default icon?


Unfortunately, there is no easy way to change the SearchView icon to a custom drawable, since the theme attribute searchViewSearchIcon is not public. See this answer for details.

However, I think that your problem is caused by inheriting from the wrong theme. Please use android:Theme.Holo.Light.DarkActionBar as the base for your theme. Then the default icons on the action bar should have a light color.

<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">    ...</style> 


Since the searchViewSearchIcon attribute is not public, you can change the icon using the following code:

int searchIconId = searchView.getContext().getResources().getIdentifier("android:id/search_button",null, null);ImageView searchIcon = (ImageView) searchView.findViewById(searchIconId);searchIcon.setImageResource(R.drawable........);


Try to set up in the showAsAction this option: *MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW*

Without this option the SearchView do not take the icon which you setup for action button.

menu.add("Search")            .setIcon(                    getResources().getDrawable(                            R.drawable.selectable_header_search))            .setActionView(searchView)            .setShowAsAction(                    MenuItem.SHOW_AS_ACTION_ALWAYS                            | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW                            | MenuItem.SHOW_AS_ACTION_WITH_TEXT);