2013-10-29 91 views
1

我有一个searchview下面的操作栏。我尝试用另一个drawable替换x标记(关闭图标)。我尝试了下面的代码,发现此错误: 错误:错误:找到与给定名称相匹配的资源:attr'searchViewCloseIcon'。在searchview中更改x标记图标

请让我知道如何解决这个错误。我真的很感激任何帮助。提前感谢。

在styles.xml中值的文件夹

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

如果您绘制图标所在?它在你的可绘制文件夹中吗? – GrIsHu

+0

是它在可绘制的文件夹中 – jason

+0

查看我的答案。 @jason – GrIsHu

回答

2

试试如下:

<item name="android:searchViewCloseIcon">@drawable/ic_search_close</item> 
0
Try this 
    <style name="srcclose"> 
    <item name="android:searchViewCloseIcon">@drawable/ic_search_close</item> 
    </style> 
+0

粘贴在styles.xml中 - 出现错误:错误:错误:找不到与给定名称匹配的资源:attr 'android:searchViewCloseIcon'。 – jason

4

我不会去太多的细节,因为有一个很好的张贴在这里:here在适应searchview和为什么上述答案不起作用。

如果你想改变你的“X”,下面的工作来改变颜色

int crossId = searchView.getContext().getResources().getIdentifier("android:id/search_close_btn", null, null);   // Getting the 'search_plate' LinearLayout. 
    ImageView image = (ImageView) searchView.findViewById(crossId); 
    Drawable d = image.getDrawable(); 
    d.setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP); 

如果你想改变图标

int crossId = searchView.getContext().getResources().getIdentifier("android:id/search_close_btn", null, null);   // Getting the 'search_plate' LinearLayout. 
    ImageView image = (ImageView) searchView.findViewById(crossId); 
    image.setImageResource(R.drawable.NEW_ICON_HERE); 
+0

我花了不正常的时间使它工作,这似乎工作。我只是想知道为什么Android必须使字面上的东西,所有frikkin硬.... – breakline