Ad

Show Backbutton In Toolbar Using Styles

- 1 answer

I would like to pass toolbar theme to my other library's class in AndroidManifest. I have declared the theme in styles.xml as follows:

    <style name="MyTheme" parent="AppTheme">
        <item name="homeAsUpIndicator">@drawable/back</item>
        <item name="title">@string/app_name</item>
        <item name="subtitle">@string/app_version</item>
    </style>

Whereas, the back button is not visible while displaying that library's class. So is there a way to setDisplayHomeAsUpEnabled to true in styles.xml itself??

Ad

Answer

We can use, navigationIcon option to show icon using styles.xml.

If you're targetting API 21+,

<item name="android:navigationIcon">@drawable/back</item>

Otherwise,

<item name="navigationIcon">@drawable/back</item>

So, my theme should be,

<style name="MyTheme" parent="AppTheme">
        <item name="colorPrimary">@color/colorAccent</item>
        <item name="title">@string/app_name</item>
        <item name="subtitle">@string/app_version</item>
        <item name="navigationIcon">@drawable/back</item>
</style>
Ad
source: stackoverflow.com
Ad