Search code examples
androidsearchview

searchview customize close icon


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);

Solution

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

    <item name="android:searchViewCloseIcon">@android:drawable/ic_search_close</item>