1

Action provider back icon:

Action provider back icon

How do i change the back icon generated by the action provider. I have already changed the back icon in all my activities with HomeAsUpIndicator. But this generated back icon still with the default black arrow. The image above show which icon i talk about, when i click on the search icon for example.

In my activity :

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_equipment);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_chevron_left_white_48dp);

[...]

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

        MenuItem searchItem = menu.findItem(R.id.action_search);
        SearchActionProvider searchActionProvider = new SearchActionProvider(this);
        MenuItemCompat.setActionProvider(searchItem, searchActionProvider);

        return super.onCreateOptionsMenu(menu);
    }
Nikola Despotoski
  • 49,966
  • 15
  • 119
  • 148
Thomas B.
  • 31
  • 5

3 Answers3

2

It works with this line :

app:collapseIcon="@drawable/ic_chevron_left_white_48dp"

Put it here :

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar_equipment"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    app:title="@string/equipments"
    app:titleTextColor="@color/white"
    android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    app:collapseIcon="@drawable/ic_chevron_left_white_48dp" />
Thomas B.
  • 31
  • 5
0

Edit your styles.xml and add the following:

<style name="AppTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
    <item name="android:actionBarStyle">@style/CustomActionBar</item>
</style>

<style name="CustomActionBar" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
    <item name="android:icon">@drawable/ic_close</item>
</style>
Javier S.
  • 756
  • 8
  • 9
0

get the SupportActionbar and specfiy the id of the icon

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_close);
  • I already do that in my activity, but the icon generated when i active the action provider doesn't change. – Thomas B. May 31 '16 at 14:25
  • make sure that the right toolbar is set `setSupportActionBar(yourToolBar);` – Zouhair ISKSIOU May 31 '16 at 14:30
  • take a look at this : [customize the up button when the searchview is being expanded](http://stackoverflow.com/questions/27348479/how-to-customize-the-up-button-when-the-searchview-is-being-expanded) – Zouhair ISKSIOU May 31 '16 at 14:37