searchview customize close icon

自作多情 提交于 2021-01-28 13:22:01

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!