public void setUp(int fragmentId, DrawerLayout drawerLayout) {
        mFragmentContainerView = getActivity().findViewById(fragmentId);
        mDrawerLayout = drawerLayout;
        mActionBarToolbar = (Toolbar) getActivity().findViewById(R.id.toolbar);

        // set a custom shadow that overlays the main content when the drawer opens
        mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
        // set up the drawer's list view with items and click listener

        // ActionBarDrawerToggle ties together the the proper interactions
        // between the navigation drawer and the action bar app icon.
        mDrawerToggle = new JToggle(
                getActivity(),                    /* host Activity */
                mDrawerLayout,                    /* DrawerLayout object */
                mActionBarToolbar,             /* nav drawer image to replace 'Up' caret */
                R.string.navigation_drawer_open,  /* "open drawer" description for accessibility */
                R.string.navigation_drawer_close  /* "close drawer" description for accessibility */
        ) {
            @Override
            public void onDrawerClosed(View drawerView) {
                super.onDrawerClosed(drawerView);
                if (!isAdded()) {
                    return;
                }

                getActivity().supportInvalidateOptionsMenu(); // calls onPrepareOptionsMenu()
            }

            @Override
            public void onDrawerOpened(View drawerView) {
                super.onDrawerOpened(drawerView);
                if (!isAdded()) {
                    return;
                }

                if (!mUserLearnedDrawer) {
                    // The user manually opened the drawer; store this flag to prevent auto-showing
                    // the navigation drawer automatically in the future.
                    mUserLearnedDrawer = true;
                    SharedPreferences sp = PreferenceManager
                            .getDefaultSharedPreferences(getActivity());
                    sp.edit().putBoolean(PREF_USER_LEARNED_DRAWER, true).apply();
                }

                getActivity().supportInvalidateOptionsMenu(); // calls onPrepareOptionsMenu()
            }
        };

        // If the user hasn't 'learned' about the drawer, open it to introduce them to the drawer,
        // per the navigation drawer design guidelines.
        if (!mUserLearnedDrawer && !mFromSavedInstanceState) {
            mDrawerLayout.openDrawer(mFragmentContainerView);
        }

        // Defer code dependent on restoration of previous instance state.
        mDrawerLayout.post(new Runnable() {
            @Override
            public void run() {
                mDrawerToggle.syncState();
            }
        });

        mDrawerLayout.setDrawerListener(mDrawerToggle);
    }
public void setUp ( int fragmentId , DrawerLayout drawerLayout ) { mFragmentContainerView = getActivity ( ) . findViewById ( fragmentId ) ; mDrawerLayout = drawerLayout ; mActionBarToolbar = ( Toolbar ) getActivity ( ) . findViewById ( R . id . toolbar ) ; mDrawerLayout . setDrawerShadow ( R . drawable . drawer_shadow , GravityCompat . START ) ; mDrawerToggle = new JToggle ( getActivity ( ) , mDrawerLayout , mActionBarToolbar , R . string . navigation_drawer_open , R . string . navigation_drawer_close ) { @ Override public void onDrawerClosed ( View drawerView ) { super . onDrawerClosed ( drawerView ) ; if ( ! isAdded ( ) ) { return ; } getActivity ( ) . supportInvalidateOptionsMenu ( ) ; } @ Override public void onDrawerOpened ( View drawerView ) { super . onDrawerOpened ( drawerView ) ; if ( ! isAdded ( ) ) { return ; } if ( ! mUserLearnedDrawer ) { mUserLearnedDrawer = true ; SharedPreferences sp = PreferenceManager . getDefaultSharedPreferences ( getActivity ( ) ) ; sp . edit ( ) . putBoolean ( PREF_USER_LEARNED_DRAWER , true ) . apply ( ) ; } getActivity ( ) . supportInvalidateOptionsMenu ( ) ; } } ; if ( ! mUserLearnedDrawer && ! mFromSavedInstanceState ) { mDrawerLayout . openDrawer ( mFragmentContainerView ) ; } mDrawerLayout . post ( new Runnable ( ) { @ Override public void run ( ) { mDrawerToggle . syncState ( ) ; } } ) ; mDrawerLayout . setDrawerListener ( mDrawerToggle ) ; }
Users of this fragment must call this method to set up the navigation drawer interactions.

@param fragmentId   The android:id of this fragment in its activity's layout.
@param drawerLayout The DrawerLayout containing this fragment's UI.