I'm trying out androidx navigation component and have setup my activity with a toolbar a container. I'm doing this in one of the intermittent screens of my app which has a lot of internal navigation/steps and I thought I could navigation arch component a try with this.
Since this is an intermittent screen, I want to display a back button on the toolbar from the first screen itself.
I've already setup the toolbar with the below code in the onCreate() method of my host activity,
setSupportActionBar(toolbar);
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
NavigationUI.setupActionBarWithNavController(this, navHostFragment.getNavController());
I can see the back button/back arrow on the second screen of my graph but not on the first screen.
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/navigation"
app:startDestination="@id/listing">
<fragment
android:id="@+id/listing"
android:name=".ui.ItemsListingFragment"
android:label="Items"
tools:layout="@layout/items_listing" >
<action
android:id="@+id/listToQuantity"
app:destination="@id/quantity"
/>
<action
android:id="@+id/listToReason"
app:destination="@id/reason"
/>
</fragment>
<fragment
android:id="@+id/quantity"
android:name=".ui.ItemQuanitySelectionFragment"
android:label="Items"
tools:layout="@layout/fragment_item_quanity_selection" >
<action
android:id="@+id/quantityToReason"
app:destination="@id/reason"
/>
</fragment>
<fragment
android:id="@+id/reason"
android:name=".ui.ItemReasonFragment"
android:label="Items"
tools:layout="@layout/fragment_item_reason">
</fragment>
</navigation>
What more changes do I need to make to add the back button on the toolbar right from the first step.