2

I have a searchview below action bar .I tried replacing the x mark(close icon) with another drawable .I tried the code below and i am getting this error: error: Error: No resource found that matches the given name: attr 'searchViewCloseIcon'.

please let me know how to resolve this error .I really appreciate any help .Thanks in advance.

in styles.xml in values folder

<style name="Theme" parent="AppBaseTheme">
<item name="android:searchViewCloseIcon">@android:drawable/ic_search_close</item>
</style>
Community
  • 1
  • 1
jason
  • 3,932
  • 11
  • 52
  • 123

3 Answers3

4

I won't go into too much detail because there's an excellent post here: here in regards to adapting the searchview and why the above answers will not work.

If you would like to change your 'X', the following works to change the color

   int crossId = searchView.getContext().getResources().getIdentifier("android:id/search_close_btn", null, null);            // Getting the 'search_plate' LinearLayout.
    ImageView image = (ImageView) searchView.findViewById(crossId);
    Drawable d = image.getDrawable();
    d.setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP);

If you would like to change the icon

   int crossId = searchView.getContext().getResources().getIdentifier("android:id/search_close_btn", null, null);            // Getting the 'search_plate' LinearLayout.
    ImageView image = (ImageView) searchView.findViewById(crossId);
    image.setImageResource(R.drawable.NEW_ICON_HERE);
Community
  • 1
  • 1
LifeQuestioner
  • 406
  • 5
  • 14
  • I spent an unholy amount of time to make it work and this seems to work. I'm just wondering why Android has to make literally everything so frikkin hard.... – breakline Oct 04 '16 at 23:11
2

Try out as below:

 <item name="android:searchViewCloseIcon">@drawable/ic_search_close</item>
GrIsHu
  • 29,068
  • 10
  • 64
  • 102
0
Try this
    <style name="srcclose">   
    <item name="android:searchViewCloseIcon">@drawable/ic_search_close</item>
    </style>
APriya
  • 1,994
  • 1
  • 16
  • 21
  • pasted in styles.xml - getting an error : error: Error: No resource found that matches the given name: attr 'android:searchViewCloseIcon'. – jason Oct 29 '13 at 05:06