searchview 自定义关闭图标 [英] searchview customize close icon
问题描述
我使用下面的代码不起作用:错误:错误:找不到与给定名称匹配的资源:attr'searchViewCloseIcon'.如何更改 searchview 中的关闭图标.我非常感谢您的帮助.提前致谢.我也看到了这个链接 Android SearchView X 标记图标 但无法实现它.也不是操作栏仅搜索视图
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
在值文件夹中的styles.xml
in styles.xml in values folder
<style name="Theme" parent="AppBaseTheme">
<item name="android:searchViewCloseIcon">@android:drawable/ic_search_close</item>
</style>
我试过这个代码:
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);
推荐答案
如果你有AppCompat SearchView,你必须设置searchViewCloseIcon而没有android"
if you have AppCompat SearchView, you have to set searchViewCloseIcon without "android"
<item name="android:searchViewCloseIcon">@android:drawable/ic_search_close</item>
这篇关于searchview 自定义关闭图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!