Alex Smith Alex Smith - 9 days ago 5
Android Question

How to change SearchView elements' color?

I want to use SearchView in my project, but I have a problem with elements' color. Let me show you: its fragmentDialog where I have my SearchView
You can see what I mean here
I dont need to change bg color. The next picture is for example. I want to see SearchView elements without black bg.
The color of the elements is white
I have tried to


  • change theme

  • change style

  • change tint



but nothing is working. The search icon and anoter elements still white. Maybe I'm losing something? Can I do this in XML? Please, help me.

Answer

You need to use android.support.v7.widget.SearchView

try with this style in your searchview, Before expanding searchview

After expanding searchview

<android.support.v7.widget.SearchView xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/search_view"
            style="@style/SearchViewStyle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:layout_centerVertical="true"
            android:layout_gravity="end" />

<style name="SearchViewStyle" parent="Widget.AppCompat.SearchView">
    <!-- Gets rid of the search icon -->
    <item name="searchIcon">@drawable/ic_search</item>
    <!-- Gets rid of the "underline" in the text -->
    <item name="queryBackground">@color/white</item>
    <!-- Gets rid of the search icon when the SearchView is expanded -->
    <item name="searchHintIcon">@null</item>
    <!-- The hint text that appears when the user has not typed anything -->
    <item name="queryHint">@string/search_hint</item>
</style>
Comments