2013-10-29 92 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