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);
androidx.appcompat.widget.Toolbar. A standard toolbar for use within application content. A Toolbar is a generalization of action bars for use within application layouts.
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
Just add this line to your styles.xml
<item name="navigationIcon">@drawable/ic_back_arrow</item>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With