0

I want to have the same drawer in all of my activities without having to manually:

  • Copy paste it in each activity layout file.
  • Populate it with the same content
  • Store and remember its state

Are any or all of these points achievable?

SpaceMonkey
  • 3,855
  • 4
  • 32
  • 56

1 Answers1

1

Just create a BaseActivity class that implements the drawer, and let all your other activities extend this one.

The below links could help you:

Android: Navigation-Drawer on all activities

Android Navigation Drawer on multiple Activities

U can replace the setContentView of Activity as given.

//  setContentView(R.layout.activity_main);

    LayoutInflater inflater = (LayoutInflater) getApplicationContext()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View contentView = inflater.inflate(R.layout.activity_main, null, false);
    drawerLayout.addView(contentView, 0);
Community
  • 1
  • 1
prat
  • 795
  • 5
  • 14
  • But then when the base activity call SetContentView to the drawer layout won't that conflict with this activitiy's SetContentView?? – SpaceMonkey Oct 04 '15 at 19:45
  • Its ok, np, well u can also check my edits and pls tick green in the cjheckbox if the solution resolved your question – prat Oct 04 '15 at 20:07
  • The example code you gave is not clear, I think the first answer in the first link explains it pretty well. – SpaceMonkey Oct 04 '15 at 20:14