2013-10-28 36 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" 

希望它可以幫助別人。