2013-10-28 54 views
1

我用下面的代码它没有工作:错误:错误:找不到匹配给定名称的资源:attr 'searchViewCloseIcon'。如何更改searchview中的关闭图标。我真的很感激任何在advance.I help.Thanks也看到了这个链接Android SearchView X mark icon,但不能执行它。还有它不是操作栏只搜索视图searchview自定义关闭图标

在styles.xml中值的文件夹

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

上面的工作,但下面的一个没有。

 int linlayId = getResources().getIdentifier("android:id/search_close_btn", null, null); 
     ViewGroup v = (ViewGroup) src.findViewById(linlayId); 
     v.setBackgroundResource(R.drawable.ic_launcher); 

回答

1

如果你有程序兼容性搜索查看,你必须设置searchViewCloseIcon没有“Android”的

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

这不起作用,你只能使用默认的SDK。在那里这是一个私人属性。当使用appCompat或第三方操作栏时,该(可能)工作。 – SjoerdvGestel

3

的search_close_btn是ImageView的,并设置其背景不会为这一个工作。 尝试以下操作:

int closeButtonId = searchView.getContext().getResources().getIdentifier("android:id/search_close_btn", null, null); 
     ImageView closeButton = (ImageView) searchView.findViewById(closeButtonId); 
     closeButton.setImageResource(R.drawable.mydrawable); 
+2

我使用默认的SDK的操作栏,这对我很有用。 – waynesford

1

刚刚发现的程序兼容性搜索查看十字图标随机变通

app:closeIcon="@drawable/delete" 

希望它可以帮助别人。