title: How to catch navigation icon click on toolbar from fragment?
body: <p>I have a dialog fragment in which I have toolbar in layout. 
  I want to make back button(Navigation Icon) working in toolbar and exit the fragment when clicked. But I am unable to catch the click event on the toolbar's navigation icon in the (dialog)fragment.</p>
  
  <p>Here is how I am getting toolbar :</p>
  
  <pre><code>toolbar = (Toolbar) rootView.findViewById(R.id.toolbar);
  toolbar.setNavigationIcon(R.drawable.abc_ic_ab_back_mtrl_am_alpha);
  toolbar.setTitle(itemType);
  ((AppCompatActivity)getActivity()).setSupportActionBar(toolbar);
  </code></pre>
  
  <p>Here is my layout file for the dialog fragment : </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout          xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      android:orientation="vertical"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:background="@color/panel_cyan"
      android:id="@+id/rootLayout"
      &gt;
  
  &lt;android.support.v7.widget.Toolbar
      android:id="@+id/toolbar"
      android:layout_width="match_parent"
      android:layout_height="?attr/actionBarSize"
      android:layout_alignParentLeft="true"
      android:layout_alignParentStart="true"
      android:layout_alignParentTop="true"
      android:background="@color/color_primary"
      android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
      app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /&gt;
  
  &lt;ListView
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:id="@+id/listViewItems"
      /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>**Here is what is have tried so far but failed **</p>
  
  <p>Options item click in id R.id.home</p>
  
  <pre><code> @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          int id = item.getItemId();
          switch (id){
              case android.R.id.home:
                  finish();
                  break;
          }
          return super.onOptionsItemSelected(item);
      }
  </code></pre>
  
  <p>setNavigationOnClick() on the toolbar :</p>
  
  <pre><code>toolbar.setNavigationOnClickListener(new View.OnClickListener(){
              @Override
              public void onClick(View view) {
                  Toast.makeText(getActivity(), "Back clicked!",     Toast.LENGTH_SHORT).show();
              }
          });
  </code></pre>