There is two ways to do this.
Using navigation view app:headerLayout="@layout/yourLayout"
and setting a layout that you create whatever you want, then and your code:
NavigationView nav = (NavigationView) findViewById(R.id.yourNav);
Switch switch = (Switch) nav.getHeaderView(0).findViewById(R.id.yourSwitch);
The second way to do this is using a custom library like this one: SublimeNavigationView
1
solved How to custom menu like this