0

In my application on the dashboard, there is an application bar that looks something like the image below.

enter image description here

As shown in the image, I have a toolbar that currently shows the Navigation drawer.

From the navigation drawer, I can navigate to a fragment A that replaces the TAB area under the toolbar as shown in the image below.

enter image description here

Is there any way I can add two toolbars like this where I can show the navigation drawer icon and back button together inside a fragment?

ragingasiancoder
  • 616
  • 6
  • 17
Dishant Anand
  • 362
  • 1
  • 14
  • Based on your update, it looks like you found a way to achieve what you are asking. Are you just asking for a *different* way to achieve the same thing? If so, why is your current implementation not sufficient? – Bryan Jul 18 '16 at 15:01
  • I definitely found a way to achieve the problem, I was thinking if there was a best to achieve the above as the solution posted by me is more of a workaround i suppose.. – Dishant Anand Jul 18 '16 at 15:45

2 Answers2

0

There is no best way to achieve what you are looking for, considering it goes against the Android Design Guidelines. Although not explicitly stated, the navigation drawer icon and the back button icon are never displayed together.

The theory behind this design is that navigation should be intuitive and predictable, displaying two navigational icons next to each other detracts from an intuitive user interface. The back button should be displayed if there is something to go back to. Though, the need for persistent navigation can be addressed in two different ways. Take Google's Gmail app for example.

By default the NavigationView supports using a swipe from the left edge of the screen as a gesture to open the navigation drawer. In the Gmail app, the navigation drawer icon is show while you are in any one of your inboxes. As soon as a message is selected, the navigation drawer icon is replaced with the back button. Though, you will notice that you can still access the drawer using the gesture stated previously.

Gmail w/ Drawer Icon Gmail w/ Back Button

On larger screens, the Gmail app supports a miniature navigation drawer. This drawer can remain in view without the need to display to navigational icons. Though this is a little more difficult to implement with the current support library, if you are looking to, this answer may help.

Gmail w/ Persistant Drawer

Finally, to answer your question, there is no built-in way to display a back button and a navigation drawer icon together. If you need to do so, the only way would be to use a "work-around", as you currently are.

Though, the only change I would probably make is to use an ImageButton rather than an ImageView. Then you can set the style of the button using style="?android:attr/actionButtonStyle" to mimic the look of an ActionBar button.

Community
  • 1
  • 1
Bryan
  • 14,756
  • 10
  • 70
  • 125
  • Thanks Bryan, for pulling out some time and helping me with this problem.I have replaced ImageView to ImageButton now , which is definitely looking good. Cheers! – Dishant Anand Jul 18 '16 at 18:05
-2

Just to update, for the time being, to achieve the above what I have done is.

I added a layout to my fragment file where I draw a custom back button like this:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/colorPrimaryDark20"
    android:orientation="horizontal"
    android:padding="15dp"
    android:weightSum="3">
    <ImageView
        android:id="@+id/backButton"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_gravity="left"
        android:layout_weight="0.2"
        android:src="@drawable/delete_icon" />
</LinearLayout>

When a person clicks on backImage, I call popBackStack.

   imageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            getFragmentManager().popBackStack();
        }
    });

The above code gives me the desired functionality.

Note, for the above to work you need to make sure you are adding your fragmentTransaction to backstack as below

final FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.home_content_layout,NAME_OFYOUR_FRAGMENT,"nameOfYourFragment");
transaction.addToBackStack(null);
transaction.commit();
ragingasiancoder
  • 616
  • 6
  • 17
Dishant Anand
  • 362
  • 1
  • 14
  • 1
    You can always update your question (click [*edit*](http://stackoverflow.com/posts/38436040/edit)), this does not belong as an answer. – Bryan Jul 18 '16 at 14:54