Reputation: 5962
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.
Upvotes: 8
Views: 5073
Reputation: 14618
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
Upvotes: 2
Reputation: 8675
if you are searching for white icons on toolbar add these on your toolbar tag
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
Upvotes: 8
Reputation: 86
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.
Upvotes: 3