Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Searchview back button color change

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

like image 905
Surya V Avatar asked Jan 17 '17 12:01

Surya V


3 Answers

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" />
like image 106
Shubham Shukla Avatar answered Oct 16 '22 15:10

Shubham Shukla


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"/>
like image 38
Surya V Avatar answered Oct 16 '22 16:10

Surya V


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) {
}
like image 4
toto263 Avatar answered Oct 16 '22 15:10

toto263