jason
jason

Reputation: 3962

change x mark icon in searchview

I have a searchview below action bar .I tried replacing the x mark(close icon) with another drawable .I tried the code below and i am getting this error: error: Error: No resource found that matches the given name: attr 'searchViewCloseIcon'.

please let me know how to resolve this error .I really appreciate any help .Thanks in advance.

in styles.xml in values folder

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

Upvotes: 2

Views: 1552

Answers (3)

LifeQuestioner
LifeQuestioner

Reputation: 416

I won't go into too much detail because there's an excellent post here: here in regards to adapting the searchview and why the above answers will not work.

If you would like to change your 'X', the following works to change the color

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

If you would like to change the icon

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

Upvotes: 4

APriya
APriya

Reputation: 2004

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

Upvotes: 0

GrIsHu
GrIsHu

Reputation: 23638

Try out as below:

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

Upvotes: 2

Related Questions