You can bind Navigation drawer with one activity. Navigation drawer will display in only activity in which you have created. if you want to view navigation drawer in all application, you can add one frame layout and add fragments there for application functionality. That app will be a single activity with multiple fragments.
Following is code to add fragment. :
Fragment fragment = new PlanetFragment();
Bundle args = new Bundle();
args.putInt(PlanetFragment.ARG_PLANET_NUMBER, position);
fragment.setArguments(args);
// Insert the fragment by replacing any existing fragment
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.content_frame, fragment)
.commit();
For more details: Check this link. https://developer.android.com/training/implementing-navigation/nav-drawer.html
EDIT
Without Fragment
You can create one BaseActivity
, all activity
will be extended BaseActivity
. You need to bind your navigation drawer
with BaseActivity
. This way, you can achieve what you want.
BaseActivity.Java
public class BaseActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
DrawerLayout fullView = (DrawerLayout)
getLayoutInflater().inflate(R.layout.activity_base, null);
FrameLayout activityContainer = (FrameLayout)
fullView.findViewById(R.id.activity_content);
getLayoutInflater().inflate(layoutResID, activityContainer, true);
super.setContentView(fullView);
}
}