更改背景颜色,SearchView 中的查询背景颜色失败

Change the background colour and the query-background colour in SearchView fails

我正在尝试更改 SearchView 的颜色,但是当我尝试遵循 xml 代码

<SearchView
                android:id="@+id/search_view_id"
                android:layout_width="250dp"
                android:layout_height="wrap_content"
                android:queryHint="Search"
                android:iconifiedByDefault="false"
                android:layout_gravity="center"
                android:background="@color/colorPrimary"
                android:queryBackground="#FFF"/>

我收到一条错误消息:

Error:error: '#FFF' is incompatible with attribute android:queryBackground (attr) reference.

我做错了什么?

似乎 android:queryBackground 只接受资源 ID。只需使用颜色资源而不是硬编码的十六进制。请牢记这一点。

Attribute queryBackground is only used in API level 21

 <color name="white">#FFFFFF</color>

 <SearchView
    android:id="@+id/search_view_id"
    android:layout_width="250dp"
    android:layout_height="wrap_content"
    android:queryHint="Search"
    android:iconifiedByDefault="false"
    android:layout_gravity="center"
    android:background="@color/colorPrimary"
    android:queryBackground="@color/white"/>