I want to customize back and clear icon in SearchView when it collapses. My requirement is to change the color to white but now it is black.(Please refer the image shared below). I am looking to fix this issue for a couple of days, but none of the solution which I tried had not worked out. I tried few of the solutions suggested from SO like as follows:
Solution 1:
<style name="AppTheme" parent="@style/Theme.Base.AppCompat.Light.DarkActionBar">
<item name="actionBarWidgetTheme">@style/YourActionBarWidget</item>
</style>
<style name="YourActionBarWidget" parent="@style/Theme.AppCompat">
<item name="searchViewCloseIcon">@drawable/xxx</item>
</style>
Solution 2:
final Drawable upArrow = getResources().getDrawable(R.drawable.abc_ic_ab_back_mtrl_am_alpha);
upArrow.setColorFilter(getResources().getColor(R.color.WHITE), PorterDuff.Mode.SRC_ATOP);
getSupportActionBar().setHomeAsUpIndicator(upArrow);
My project styles.xml
<style name="ToolBarTheme" parent="@style/Theme.AppCompat.Light">
<item name="colorPrimary">@color/blue</item>
<item name="colorPrimaryDark">@color/blue</item>
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
<item name="android:itemTextAppearance">@style/myCustomMenuTextApearance</item>
<item name="android:actionMenuTextColor">@color/white</item>
<item name="actionMenuTextColor">@color/white</item>
</style>
<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
<item name="spinBars">true</item>
<item name="color">@color/white</item>
<item name="gapBetweenBars">2.5dip</item>
<item name="thickness">2dp</item>
</style>
Screenshot of My exact problem:
Kindly please help me to resolve my issue. Any kind of solutions and suggestions would be much helpful for me. Thanks for your support.
Change the text colors and icons of searchview in action bar. Expand the search view by setting iconified and iconifiedByDefault flags to false. Find views inside the search view and set the colors as per your wish. Find views of the icons you wish to change and replace them with your icons.
SearchView widget can be implemented over ToolBar/ActionBar or inside a layout. SearchView is by default collapsible and set to be iconified using setIconifiedByDefault(true) method of SearchView class. For making search field visible, SearchView uses setIconifiedByDefault(false) method.
Add the Search View to the App Bar To add a SearchView widget to the app bar, create a file named res/menu/options_menu. xml in your project and add the following code to the file. This code defines how to create the search item, such as the icon to use and the title of the item.
if you are searching for white icons on toolbar add these on your toolbar tag
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
I am assuming you are using this as your base application theme.
<style name="AppTheme" parent="@style/Theme.Base.AppCompat.Light.DarkActionBar">
Just change it to
<style name="AppTheme" parent="@style/Theme.AppCompat.NoActionBar">
Worked for me if you only want to change the back and X icon to white.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With