How to change SearchView elements' color?

Alex Smith picture Alex Smith · Nov 24, 2016 · Viewed 40.9k times · Source

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

Rahul Raveendran picture Rahul Raveendran · Nov 24, 2016

In this answer I assume that, the SearchView is added inside Toolbar and AppTheme is a child of Theme.AppCompat.Light.NoActionBar

<style name="AppTheme.Toolbar" parent="AppTheme">
    <!--This line changes the color of text in Toolbar-->
    <item name="android:textColorPrimary">@color/green</item>
    <!--This line changes the color of icons in toolbar (back, overflow menu icons)-->
    <item name="android:textColorSecondary">@color/green</item>
</style>

Now use the AppTheme.Toolbar as your toolbar's theme.

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    app:popupTheme="@style/AppTheme.PopupOverlay"
    app:theme="@style/AppTheme.Toolbar" />