ActionBar 中 SearchView 的主题

Theme for SearchView in ActionBar

我在 ActionBar 中有一个 SearchView

这个 SearchView 图标是黑色的,文字也是黑色的,而我的图标是白色的!

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<item
    android:id="@+id/action_search"
    android:title="@string/menu_search"
    android:icon="@drawable/ic_search"
    app:actionViewClass="android.support.v7.widget.SearchView"
    app:showAsAction="always" />
</menu>

我希望我的 SearchView 是白色的。

这里在menu.xml添加,

    <item
android:id="@+id/action_search"
android:icon="@drawable/icon"
android:title="Search"
app:actionViewClass="android.support.v7.widget.SearchView"
app:showAsAction="always"/>

在 style.xml 中你需要像这样应用样式

    <style name=”Theme.MyTheme” parent=”Theme.AppCompat”>
    <item name=”searchViewStyle”>@style/MySearchViewStyle</item>
</style>
<style name=”MySearchViewStyle” parent=”Widget.AppCompat.SearchView”>
    <!-- Background for the search query section (e.g. EditText) -->
    <item name="queryBackground">...</item>
    <!-- Background for the actions section (e.g. voice, submit) -->
    <item name="submitBackground">...</item>
    <!-- Close button icon -->
    <item name="closeIcon">...</item>
    <!-- Search button icon -->
    <item name="searchIcon">...</item>
    <!-- Go/commit button icon -->
    <item name="goIcon">...</item>
    <!-- Voice search button icon -->
    <item name="voiceIcon">...</item>
    <!-- Commit icon shown in the query suggestion row -->
    <item name="commitIcon">...</item>
    <!-- Layout for query suggestion rows -->
    <item name="suggestionRowLayout">...</item>
</style>

最后在清单文件中:

    <application...
android:theme="@style/Theme.MyTheme" >

参考:Android appcompact library 希望这对您有所帮助!