6

How to change the color of black arrow(Back button) in searchview I have tried by customizing with below code

    ImageView backid = (ImageView) searchViewAndroidActionBar.findViewById(R.id.search_button);
    backid.setColorFilter(ContextCompat.getColor(Shopping_CategoriesCommon.this, R.color.white), PorterDuff.Mode.SRC_IN);
    backid.setImageResource(R.drawable.search);

but it doesn't work

Charuක
  • 12,953
  • 5
  • 50
  • 88
Surya V
  • 399
  • 3
  • 9
  • refer http://stackoverflow.com/questions/26788464/how-to-change-color-of-the-back-arrow-in-the-new-material-theme – sasikumar Jan 17 '17 at 12:41

3 Answers3

16

Add this attribute to your toolbar in xml file app:collapseIcon

<android.support.v7.widget.Toolbar
     android:id="@+id/toolbar"
     android:layout_width="match_parent"
     android:layout_height="@dimen/toolbarHeight"
     app:collapseIcon="@drawable/collapseBackIcon" />
Shubham Shukla
  • 988
  • 2
  • 13
  • 28
11

After a day search i resolved it by adding app:collapseIcon="@drawable/back_arrow" to the custom toolbar

<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/colorPrimary"
    android:orientation="vertical"
    app:collapseIcon="@drawable/back_arrow"/>
Charuක
  • 12,953
  • 5
  • 50
  • 88
Surya V
  • 399
  • 3
  • 9
4

I could change the color using Reflection.

try {
    final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    Field mCollapseIcon = toolbar.getClass().getDeclaredField("mCollapseIcon");
    mCollapseIcon.setAccessible(true);
    Drawable drw = (Drawable) mCollapseIcon.get(toolbar);
    drw.setTint(color);
}
catch (Exception e) {
}
toto263
  • 81
  • 5