1

I used the code below it did not work : error: Error: No resource found that matches the given name: attr 'searchViewCloseIcon'.How do I change the close icon in searchview .I really appreciate any help.Thanks in advance.I also saw this link Android SearchView X mark icon but cannot implement it .Also its not action bar only search view

in styles.xml in values folder

<style name="Theme" parent="AppBaseTheme">
<item name="android:searchViewCloseIcon">@android:drawable/ic_search_close</item>
</style>

I tried this code :

        int linlayId = getResources().getIdentifier("android:id/search_plate", null, null);
        ViewGroup v = (ViewGroup) src.findViewById(linlayId);
        v.setBackgroundResource(R.drawable.ic_launcher);

the one above works but the one below does not.

        int linlayId = getResources().getIdentifier("android:id/search_close_btn", null, null);
        ViewGroup v = (ViewGroup) src.findViewById(linlayId);
        v.setBackgroundResource(R.drawable.ic_launcher);
Community
  • 1
  • 1
jason
  • 3,932
  • 11
  • 52
  • 123

3 Answers3

4

The search_close_btn is an imageview, setting its background will not work for this one. try the following:

 int closeButtonId = searchView.getContext().getResources().getIdentifier("android:id/search_close_btn", null, null);
        ImageView closeButton = (ImageView) searchView.findViewById(closeButtonId);
        closeButton.setImageResource(R.drawable.mydrawable);
SjoerdvGestel
  • 391
  • 2
  • 14
2

Just found a random workaround for Appcompat Searchview cross icon

 app:closeIcon="@drawable/delete"

Hope it helps someone.

Ashish Shukla
  • 1,027
  • 16
  • 36
1

if you have AppCompat SearchView, you have to set searchViewCloseIcon without "android"

<item name="android:searchViewCloseIcon">@android:drawable/ic_search_close</item>
AndrewS
  • 7,418
  • 8
  • 35
  • 50
  • 1
    This will not work you only use the default SDK. In there this is a private attribute. When using the appCompat or a 3rd party actionbar this (might) work though. – SjoerdvGestel Aug 26 '14 at 13:28