How to change HomeAsUp indicator in new AppCompat Toolbar?

dasar picture dasar · Nov 6, 2014 · Viewed 45.1k times · Source

I wanna change default ActionBar homeAsUp indicator (drawable) in my AppCompat Toolbar. How to achieve that? Only default arrow shows up.

styles (same for other API's level):

<style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">

        <!-- API 14 theme customizations can go here. -->
        <item name="android:windowActionBarOverlay">true</item>
        <item name="android:homeAsUpIndicator">@drawable/home</item>

        <!-- Support library compatibility -->
        <item name="windowActionBarOverlay">true</item>
        <item name="homeAsUpIndicator">@drawable/home</item>
</style>

Toolbar in my fragment layout:

<android.support.v7.widget.Toolbar
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/my_awesome_toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/transparent"
        android:homeAsUpIndicator="@drawable/home"
        android:minHeight="?attr/actionBarSize"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        app:theme="@style/AppTheme" />

In Fragment:

toolbar = (Toolbar) rootView.findViewById(R.id.my_awesome_toolbar);

        activity.setSupportActionBar(toolbar);

        ActionBar actionBar = activity.getSupportActionBar();
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setDisplayShowTitleEnabled(false);

Answer

dasar picture dasar · Nov 6, 2014

To change icon just call at runtime:

toolbar.setNavigationIcon(R.drawable.home);

Trick with styles/themes not working.

How to enable homeAsUp or call setDisplayHomeAsUpEnabled() on standalone toolbar with appcompat v21