Search code examples
androidsearchview

Hint text color for SearchView


How to set Hint text color in SearchView?

<SearchView
                android:id="@+id/search_view"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:iconifiedByDefault="false"
                android:transitionGroup="true" />

I tried :

<item name="android:textColorHint">@android:color/grey</item>

And :

<string name="search_hint">Search for a contact<font fgcolor="#ffbbbbbb"></font></string>

But none of them applied hint text color.


Solution

  • You can set the hint text color by setting a theme to your SearchView.

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

    And in your styles.xml create the style.

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