ThorChiam
ThorChiam

Reputation: 173

change color of left back button of searchview

I want to change the color of back button in searchView(not the one of actionBar), but after a lot of tryings(customise a searchView/replace icon) just could not find any solution.The arrow on the left of the search icon should be white but I cannot change it. Hope somebody could do me a favour on this, really urge!!!

enter image description here

Part of sourceCode:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<item
    android:id="@+id/search_action_search"
    android:icon="@drawable/icon_search_selector"
    android:title="@string/search_title"
    app:actionViewClass="android.support.v7.widget.SearchView"
    app:showAsAction="always|collapseActionView" /></menu>


@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    inflater.inflate(R.menu.menu_search, menu);
    final MenuItem searchItem = menu.findItem(R.id.search_action_search);
    SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
    if (searchItem != null) {
        SearchView searchView = (SearchView) searchItem.getActionView();

Upvotes: 2

Views: 3612

Answers (3)

Borja
Borja

Reputation: 1289

The only solution worked for me was putting this in my app styles theme. The back button image drawable has the color I need.

<item name="android:homeAsUpIndicator">@drawable/back_button_image</item>

Upvotes: 1

moore
moore

Reputation: 86

Check your styles.xml for the base application theme, usually named AppTheme and change the parent to another theme. I used to have the same problem as you, black SearchView icon and arrow. But I changed the parent from Theme.AppCompat.Light.DarkActionBar to Theme.AppCompat.NoActionBar because I have my own toolbar as an action bar, and the SearchView icon and arrow changed to white.

Upvotes: 4

ThorChiam
ThorChiam

Reputation: 173

Still cannot change the color, but to simply remove the arrow, I changed app:showAsAction="always|collapseActionView" to app:showAsAction="always" and it works.

Upvotes: 0

Related Questions