In your activity layout you should add NavigationView to the drawerLayout as follows:
<android.support.v4.widget.DrawerLayout>
...
<android.support.design.widget.NavigationView
android:id="@+id/navigation"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="right"
app:itemIconTint="#333"
app:itemTextColor="#333">
<fragment
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:name="fragments.MenuFragment"
android:id="@+id/fragment"/>
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
In your MenuFragment layout you have something like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="@+id/header"
layout="@layout/nav_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/menuRecyclerView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/header"/>
</RelativeLayout>
And in the class of your fragment you can do this:
public class MenuFragment extends Fragment {
RecyclerView recyclerView;
ArrayList<MenuItem> menuItems = new ArrayList<>();
private OnFragmentInteractionListener mListener;
public MenuFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.menu_fragment, container, false);
recyclerView = root.findViewById(R.id.menuRecyclerView);
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
recyclerView.setAdapter(adapter);
recyclerView.addOnItemTouchListener(...);//add the code to handle menu click...
return root;
}
EDIT
nav_header.xml is actually the header of the navigation view and is nothing special:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="@+id/relativeLayout2"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimaryDark"
android:padding="10dp">
<ImageView
android:id="@+id/logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:paddingBottom="20dp"
android:src="@drawable/ic_white"/>
<RelativeLayout
android:id="@+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/logo">
<ImageView
android:id="@+id/account"
android:layout_width="52dp"
android:layout_height="52dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="2dp"
android:src="@drawable/ic_account_box_white_48dp"/>
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_marginEnd="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginStart="10dp"
android:layout_toLeftOf="@+id/account"
android:ellipsize="marquee"
android:singleLine="true"
android:text="UserName"
android:textColor="#ffffff"/>
</RelativeLayout>
</RelativeLayout>
The menuRecyclerView is just a recyclerView which is responsible for showing the menu items and you have to add the items to that (You can see this or this for getting started with recyclerView)
Once you added the items you are going to need to add the OnItemClickListener to the recycler view which you can learn here
And after all that is done you can start another activity like this:
Intent newActivity = new Intent(getActivity(), newActivity.class);
startActivity(newActivity);