How to change Menu SearchView Widget Icon Color In Android
SearchView Widget in Android is used to search a query and submit a request to a search provider, Which shows the suggestions list on the basis of the search query.
Recently I have been working in an android application in which SearchView Widget
used in the menu.xml file. You can see the code from the below gist.
<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> <item android:id="@id/menu_action_search" android:orderInCategory="1" android:icon="@drawable/ic_menu_search_blue" app:iconTint="#008aff" app:showAsAction="always" app:actionViewClass="android.support.v7.widget.SearchView" android:title="@string/menu_search"/> </menu>
The menu file is used in the toolbar & I noticed that the menu searchView icon is showing the right color in below Oreo and showing the wrong icon color in android Oreo.
<android.support.design.widget.AppBarLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <android.support.v7.widget.Toolbar android:id="@id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/savyour_logo" android:layout_gravity="center" android:contentDescription="@string/content_description" /> </android.support.v7.widget.Toolbar> </android.support.design.widget.AppBarLayout>
Note:
This will occurs when you don’t define the theme in your toolbar, After a lot of research, I noticed that the theme of the toolbar is not defined.
How to solve this:
To solve this issue you just need to add a toolbar style in your style.xml file like below:
<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 define your style in your toolbar app:theme like below:
<android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="?attr/colorPrimary" app:theme="@style/AppTheme.Toolbar" />
That’s it now you will be able to see the SearchView widget icon color as you defined in your style.xml file.
Thanks for reading this article. Be sure to upvote this article if you found it helpful. It means a lot to me.
Congratulations @lvlasuod! You have completed the following achievement on Steemit and have been rewarded with new badge(s) :
You published your First Post
You got a First Vote
Click on the badge to view your Board of Honor.
If you no longer want to receive notifications, reply to this comment with the word
STOP
Do not miss the last post from @steemitboard:
SteemitBoard and the Veterans on Steemit - The First Community Badge.