Changing SearchView color of back and clear icon in Android Toolbar
Asked Answered
S

3

8

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:

enter image description here

Kindly please help me to resolve my issue. Any kind of solutions and suggestions would be much helpful for me. Thanks for your support.

Slaby answered 27/8, 2015 at 13:2 Comment(3)
have you tried overriding drawerToggleHandsomely
@Handsomely Thanks for your reply. Please check my update answerSlaby
what is the retionale behind having your theme extend Theme.AppCompat.LightHandsomely
S
8

if you are searching for white icons on toolbar add these on your toolbar tag

android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
Sabo answered 6/11, 2015 at 5:11 Comment(0)
J
3

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.

Jestinejesting answered 6/11, 2015 at 5:0 Comment(1)
2022 - solution still working even for API 32Demetrademetre
W
2

1: To change back button icon, add

app:collapseIcon="@drawable/back_arrow"

in android.support.v7.widget.Toolbar

2: To change clear button icon, add

ImageView searchClose = searchView.findViewById(android.support.v7.appcompat.R.id.search_close_btn);
searchClose.setImageResource(R.drawable.close);

in onCreateOptionsMenu

Waterspout answered 29/11, 2017 at 10:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.