问题
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);
回答1:
if you have AppCompat SearchView, you have to set searchViewCloseIcon without "android"
<item name="android:searchViewCloseIcon">@android:drawable/ic_search_close</item>
回答2:
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);
回答3:
Just found a random workaround for Appcompat Searchview cross icon
app:closeIcon="@drawable/delete"
Hope it helps someone.
来源:https://stackoverflow.com/questions/19645366/searchview-customize-close-icon