4

How can I change default search icon for SearchView?

<SearchView
   android:id="@+id/searchView"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content" />

I´m not using actionBar. Is it possible? How?

Pepa Zapletal
  • 2,879
  • 3
  • 39
  • 69

2 Answers2

1

Try this

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="searchViewStyle">@style/MySearchView</item>
</style>

<style name="MySearchView" parent="Widget.AppCompat.SearchView">
    <item name="searchIcon">@drawable/ic_search</item>
    <item name="closeIcon">@drawable/ic_close</item>
</style>
Stas Parshin
  • 7,973
  • 3
  • 24
  • 43
1

It´s possible to use AppCompat.

But I used small hack:

mSearchView = (SearchView) searchViewMenuItem.getActionView();
int searchImgId = getResources().getIdentifier("android:id/search_button", null, null);
ImageView v = (ImageView) mSearchView.findViewById(searchImgId);
v.setImageResource(R.drawable.your_new_icon);  

from this How to change the default icon on the SearchView, to be use in the action bar on Android? and it looks ok.

Community
  • 1
  • 1
Pepa Zapletal
  • 2,879
  • 3
  • 39
  • 69