title: Navigation drawer not open on menu icon click on toolbar
body: <p>I want to open drawer on menu icon click but it not work.see this image what i want to say....</p>
  
  <p><a href="https://i.stack.imgur.com/0gN07.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0gN07.png" alt="enter image description here"></a></p>
  
  <p>Following code work for when we slide but not work for menu icon click.</p>
  
  <p>Please check my problem and help me...</p>
  
  <p>Thanks for your valuable time...</p>
  
  <p>MainActicity.java</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity implements
      FragmentDrawerListener {
  
  private Toolbar toolbar;
  private FragmentDrawer drawerFragment;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main_activity_lay);
  
      toolbar = (Toolbar) findViewById(R.id.toolbar);
      toolbar.setNavigationIcon(getResources().getDrawable(R.drawable.ic_launcher));
      setSupportActionBar(toolbar);
      getSupportActionBar().setDisplayHomeAsUpEnabled(true);
       getSupportActionBar().setHomeButtonEnabled(true);
      drawerFragment = (FragmentDrawer) getSupportFragmentManager()
              .findFragmentById(R.id.fragment_navigation_drawer);
      drawerFragment.setUp(R.id.fragment_navigation_drawer,
              (DrawerLayout) findViewById(R.id.drawer_layout), toolbar);
      drawerFragment.setDrawerListener(this);
      displayView(0);
  }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.menu.main, menu);
      return true;
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      // Handle action bar item clicks here. The action bar will
      // automatically handle clicks on the Home/Up button, so long
      // as you specify a parent activity in AndroidManifest.xml.
      int id = item.getItemId();
      if (id == R.id.action_settings) {
          return true;
      } 
      return super.onOptionsItemSelected(item);
  }
  
  @Override
  public void onDrawerItemSelected(View view, int position) {
      displayView(position);
  }
  </code></pre>
  
  <p>FragmentDrawer.java</p>
  
  <pre><code>public class FragmentDrawer extends Fragment {
  
  private static String TAG = FragmentDrawer.class.getSimpleName();
  
  private static String[] titles = null;
  
  private RecyclerView recyclerView;
  private NavigationDrawerAdapter adapter;
  private ActionBarDrawerToggle mDrawerToggle;
  private DrawerLayout mDrawerLayout;
  private FragmentDrawerListener drawerListener;
  private View containerView;
  
  public FragmentDrawer() {
  
  }
  
  public void setDrawerListener(FragmentDrawerListener listener) {
      this.drawerListener = listener;
  }
  
  public static List&lt;NavDrawerItem&gt; getData() {
      List&lt;NavDrawerItem&gt; data = new ArrayList&lt;&gt;();
  
      // preparing navigation drawer items
      for (int i = 0; i &lt; titles.length; i++) {
          NavDrawerItem navItem = new NavDrawerItem();
          navItem.setTitle(titles[i]);
          data.add(navItem);
      }
      return data;
  }
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      titles = getActivity().getResources().getStringArray(R.array.nav_drawer_labels);
  }
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
          Bundle savedInstanceState) {
      // Inflating view layout
      View layout = inflater.inflate(R.layout.fragment_navigation_drawer, container, false);
      recyclerView = (RecyclerView) layout.findViewById(R.id.drawerList);
      adapter = new NavigationDrawerAdapter(getActivity(), getData());
      recyclerView.setAdapter(adapter);
      recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
      recyclerView.addOnItemTouchListener(new RecyclerTouchListener(getActivity(), recyclerView, new ClickListener(){
  
          @Override
          public void onClick(View view, int position) {
              drawerListener.onDrawerItemSelected(view, position);
              mDrawerLayout.closeDrawer(containerView);
          }
  
          @Override
          public void onLongClick(View view, int position) {
  
          }
  
      }));
  
      return layout;
  }
  
  /**
   * 
   * @param fragmentId
   * @param drawerLayout
   * @param toolbar
   */
  public void setUp(int fragmentId, DrawerLayout drawerLayout, final Toolbar toolbar) {
  
      containerView = getActivity().findViewById(fragmentId);
      mDrawerLayout = drawerLayout;
      mDrawerToggle = new ActionBarDrawerToggle(getActivity(), mDrawerLayout, R.string.drawer_open, R.string.drawer_close) {
          @Override
          public void onDrawerClosed(View drawerView) {
              super.onDrawerClosed(drawerView);
              getActivity().invalidateOptionsMenu();
          }
          @Override
          public void setToolbarNavigationClickListener(
                  OnClickListener onToolbarNavigationClickListener) {
              // TODO Auto-generated method stub
              super.setToolbarNavigationClickListener(onToolbarNavigationClickListener);
              Log.i("RAJAT", "I am here");
          }
  
          @Override
          public void onDrawerOpened(View drawerView) {
              super.onDrawerOpened(drawerView);
              getActivity().invalidateOptionsMenu();
          }
  
          @Override
          public void onDrawerSlide(View drawerView, float slideOffset) {
              super.onDrawerSlide(drawerView, slideOffset);
              toolbar.setAlpha(1 - slideOffset / 2);
          }
  
          @Override
          public boolean onOptionsItemSelected(MenuItem item) {
              Log.d("RAJAT", "click ON OPTION ITEM");
              if(mDrawerToggle.onOptionsItemSelected(item)) {
                  Log.d("RAJAT", "click here");
                  return true;
              }
              return super.onOptionsItemSelected(item);
          }
  
          @Override
          public void onConfigurationChanged(Configuration newConfig) {
              super.onConfigurationChanged(newConfig);
              mDrawerToggle.onConfigurationChanged(newConfig);
          }
  
      };
  
      mDrawerLayout.setDrawerListener(mDrawerToggle);
      mDrawerLayout.post(new Runnable() {
          @Override
          public void run() {
              // Sync the toggle state after onRestoreInstanceState has occurred.
              mDrawerToggle.syncState();
          }
      });
  }
  
  static class RecyclerTouchListener implements RecyclerView.OnItemTouchListener {
  
      private ClickListener clickListener;
      private GestureDetector gestureDetector;
  
      public RecyclerTouchListener(Context context, final RecyclerView recyclerView, final ClickListener clickListener) {
          // TODO Auto-generated constructor stub
          this.clickListener = clickListener;
          gestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
              @Override
              public boolean onSingleTapUp(MotionEvent e) {
                  return true;
              }
  
              @Override
              public void onLongPress(MotionEvent e) {
                  View child = recyclerView.findChildViewUnder(e.getX(), e.getY());
                  if( child != null &amp;&amp; clickListener != null) {
                      clickListener.onLongClick(child, recyclerView.getChildPosition(child));
                  }
              }
          });
      }
  
      @Override
      public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
          View child = rv.findChildViewUnder(e.getX(), e.getY());
          if (child != null &amp;&amp; clickListener != null &amp;&amp; gestureDetector.onTouchEvent(e)) {
              clickListener.onClick(child, rv.getChildPosition(child));
          }
          return false;
      }
  
      @Override
      public void onRequestDisallowInterceptTouchEvent(boolean arg0) {
  
      }
  
      @Override
      public void onTouchEvent(RecyclerView arg0, MotionEvent arg1) {
  
      }
  
  }
  
  public static interface ClickListener {
      public void onClick(View view, int position);
  
      public void onLongClick(View view, int position);
  }
  
  public interface FragmentDrawerListener {
      public void onDrawerItemSelected(View view, int position);
  }
  </code></pre>