SearchView 的提示文字颜色

Hint text color for SearchView

如何在 SearchView 中设置提示文本颜色?

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

我试过了:

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

并且:

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

但其中 none 应用了提示文本颜色。

您可以通过为您的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" />

然后在您的 styles.xml 中创建样式。

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