0

I have added search icon in menu folder and created menu.xml file for that. Here I created custom search icon with light green color from Android Image Asset.

When I added this light green color search icon in drawable and run the project, it coming with white color. And search hint and search text also coming in white. Since I have white action bar, these all search icons are not at all visible. Please help to correct this.

I have created a menu.xml file for search icon and also added search icon with light green color in drawable folders. I am using Theme.AppCompat.Light.DarkActionBar and my action bar color it set it to white.

Styles.xml

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="titleTextColor">@color/titleColor</item>
        <item name="colorControlNormal">@color/colorAccent</item>

menu.xml file :

<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:icon="@drawable/ic_action_search"
        app:showAsAction="always"
        app:actionViewClass="android.support.v7.widget.SearchView"
        android:title="@string/search_string" />
    <!--<item
        android:id="@+id/action_settings"
        android:title="Settings"/>-->
 </menu>

Activity code :

public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu, menu);
        MenuItem item = menu.findItem(R.id.action_search);

//additonal code

return super.onCreateOptionsMenu(menu);

I want custom color search icon only to be displayed in white action bar instead of white color search icon(now displaying). And search query search hint in black color. Please help...

mohammadReza Abiri
  • 1,759
  • 1
  • 9
  • 20
  • 1
    Possible duplicate of [How can i change the icon color of searchview in actionbar?](https://stackoverflow.com/questions/47684202/how-can-i-change-the-icon-color-of-searchview-in-actionbar) – Amin Pinjari Apr 18 '19 at 13:23

3 Answers3

1

what worked for me is setting foreground. that changes icon color of the searchview.

<style name="MySearchViewTheme" parent="Widget.AppCompat.SearchView">
    <item name="android:background">@color/grey_dark</item>
    <!-- Changes icons color --> 
    <item name="android:colorForeground">@color/grey_400</item>
</style>
0

The best option would be to use custom layout for items in the menu.

Also you can try to follow this article

Antonis Radz
  • 3,036
  • 1
  • 16
  • 34
0

You need to use android.support.v7.widget.SearchView :

<style name="SearchViewStyle" parent="Widget.AppCompat.SearchView">
    <!-- Gets rid of the search icon -->
    <item name="searchIcon">@drawable/ic_search</item>
    <!-- Gets rid of the "underline" in the text -->
    <item name="queryBackground">@color/white</item>
    <!-- Gets rid of the search icon when the SearchView is expanded -->
    <item name="searchHintIcon">@null</item>
    <!-- The hint text that appears when the user has not typed anything -->
    <item name="queryHint">@string/search_hint</item>
</style>
mohammadReza Abiri
  • 1,759
  • 1
  • 9
  • 20