5

Is there a way to change the color of the arrow displayed on a SearchView when its expanded? enter image description here

I have tried everything with no results.

Mr. Thanks a lot
  • 235
  • 4
  • 17
  • See this http://stackoverflow.com/questions/9252354/how-to-customize-the-back-button-on-actionbar – Rohit5k2 Feb 25 '16 at 19:20
  • This worked for me https://stackoverflow.com/questions/44904085/how-to-set-the-toolbar-collapseicon-color-programmatically – pw2 Oct 09 '18 at 06:41

5 Answers5

21

To change Back Icon color add below attribute in your android.support.v7.widget.Toolbar Toolbar

app:collapseIcon="@drawable/back_arrow"

Also to change close button icon add the following piece of code

ImageView searchClose = searchView.findViewById(android.support.v7.appcompat.R.id.search_close_btn);
searchClose.setImageResource(R.drawable.close);
MashukKhan
  • 1,946
  • 1
  • 27
  • 46
1

See Abdul Rahman's answer here (Styling a SearchView in Android Action Bar)

@Override
    public boolean onCreateOptionsMenu(Menu menu)
    {
        getMenuInflater().inflate(R.menu.main_menu, menu);
        restoreActionBar();

        SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
        MenuItem searchMenuItem = menu.findItem(R.id.action_search);
        SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchMenuItem);
        searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));

        SearchView.SearchAutoComplete searchAutoComplete = (SearchView.SearchAutoComplete)searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text);
        searchAutoComplete.setHintTextColor(Color.WHITE);
        searchAutoComplete.setTextColor(Color.WHITE);

        View searchplate = (View)searchView.findViewById(android.support.v7.appcompat.R.id.search_plate);
        searchplate.setBackgroundResource(R.drawable.texfield_searchview_holo_light);

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

        ImageView voiceIcon = (ImageView)searchView.findViewById(android.support.v7.appcompat.R.id.search_voice_btn);
        voiceIcon.setImageResource(R.drawable.abc_ic_voice_search);

        ImageView searchIcon = (ImageView)searchView.findViewById(android.support.v7.appcompat.R.id.search_mag_icon);
        searchIcon.setImageResource(R.drawable.abc_ic_search);


        return super.onCreateOptionsMenu(menu);
    }
Community
  • 1
  • 1
Usman Rana
  • 2,067
  • 1
  • 21
  • 32
0

Here is another approach:

<style name="ActivityTheme" parent="@android:style/Theme.DeviceDefault.Light">
    <item name="android:actionBarTheme">@style/searchActionBarTheme</item>
</style>

<style name="searchActionBarTheme" parent="@android:style/ThemeOverlay.Material.Dark.ActionBar">
    <item name="android:textColorPrimary">@color/back_key_color</item> <!-- back key color defined here!! -->
    <item name="android:actionBarWidgetTheme">@style/searchViewTheme</item>
</style>

<style name="searchViewTheme" parent="@android:style/ThemeOverlay.Material.Light">
    <item name="android:editTextColor">@color/edit_text_color</item>
    <item name="android:colorControlActivated">@color/search_cursor_color</item>
</style>

Use ActivityTheme for your Activity in Manifest.xml

Stepan Novikov
  • 1,402
  • 12
  • 22
Shrdi
  • 359
  • 4
  • 13
0

Change SearchView close Icon color

SearchView  searchView = (SearchView) findViewById(R.id.searchView1);

    ImageView searchClose  = (ImageView) searchView.findViewById(search.getContext().getResources().getIdentifier("android:id/search_close_btn", null, null));

    searchClose.setColorFilter (R.color.black);
damith alahakoon
  • 270
  • 4
  • 14
-1

I am using SearchView in Toolbar, and 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