Search code examples
androidsearchview

Color for Widget.AppCompat.SearchView clear text icon


I want to set color for my SearchView clear text icon(multiplication sign):

<style name="SearchViewStyle" parent="Widget.AppCompat.SearchView">
     <item name="android:textColorHint">@android:color/grey</item>
</style>

And this is my SearchView :

             <SearchView
                android:id="@+id/search_view"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginEnd="16dp"
                android:iconifiedByDefault="false"
                android:theme="@style/SearchViewStyle"
                android:transitionGroup="true" />

Which property should I use?


Solution

  • You should do this in your code behind of your activity. Something as followed:

    SearchView searchView = findViewById(R.id.search_view):
    
    int searchCloseIconButtonId = SearchView.getContext().getResources()
            .getIdentifier("android:id/search_close_btn", null, null);
    ImageView searchClose = searchView.findViewById(searchCloseIconButtonId);
    searchClose.setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP);