I am using the default ActionBar
in my android project. I am using the Theme.AppCompat.Light.DarkActionBar
theme.
I have created XML
file for menu
and the search item
from this menu
is below:
<item
android:id="@+id/search_button"
android:icon="@android:drawable/ic_menu_search"
android:title="Search"
app:showAsAction="always" />
When i load the application on physical device for testing the color of the search icon
is not white, its a kind of reddish (the low color of the ActionBar
), see the image below:
Title color is white which is OK, overflow menu button color is white which is OK, but the search icon button is not white. So, i did research and found the following sources in which no one is working.
Eventually, i realize that there is no way to change the color of the default search icon in the ActionBar
. I just want to make this question to be the last and long explanation of this issue which covers the Why the icon color is different then the title color and overflow menu icon color?
, Why this thing is impossible to solve?
, Where this color property of xml for search icon is hidden that is hard to find?
and How(if possible) to change the color of this default search icon in the ActionBar
? I know we can add the custom icon with white color here and we also have the ToolBar
, but i don't want this solution because if its possible to change the title in ActionBar
, add the overflow menu options into the ActionBar
(etc) then it should also be possible to change the color of the search icon in the ActionBar
. May be i found a hidden geek who knows this issue and can explain the Why
and What
to make this question the last informative/solution for future android folks.
If anyone want to negative mark my question, i am happily ready for this but at least this question will be helpful for the future android newbies. Thanks!!!
Why the icon color is different then the title color and overflow menu icon color?
@android:drawable/ic_menu_search
(You can find them in Android\Sdk\platforms\android-28\data\res\drawable
) is a png file with some transparent white color(That's why you get a white reddish color)
Why this thing is impossible to solve?
It's not impossible, you can create your own icon as given below in this answer.
Where this color property of xml for search icon is hidden that is hard to find?
There is no xml. Just png files. Depending on the theme android will choose one of them.(ie for Light Action bar a black icon and for Dark Action bar a white icon)
How(if possible) to change the color of this default search icon in the ActionBar?
The solution is to create your own vector image for the search icon. You can assign any color you want. Then use this icon in the menu.
Step 1: Create a Vector Image
Right Click on drawable
folder -> New -> Vector Assest
Step 2: Create a Search Icon and choose a color
Change the Clipart
and color
Step 3: Use this icon in the menu
<item
android:id="@+id/search_button"
android:icon="@drawable/ic_search_black_24dp"
android:title="Search"
app:showAsAction="always" />