How to Display Navigation Drawer in all activities?

后端 未结 8 1238
刺人心
刺人心 2020-11-27 13:39

I have a Navigation Drawer which should appear in all my activities.

I saw many questions similar to this & found a solution like Extending the Main

8条回答
  •  难免孤独
    2020-11-27 14:24

    Here is a simple and fast way to do it in android studio:

    1. Create a new activity (Navigation drawer activity) from the gallery, and name it whatever you want, android studio will create everything for you (the class and the xml files that you can customize it later)

    2. In other activities you should extend your Navigation drawer activity, and make sure these other activities has "no action bar" in the manifests file (android:theme="@style/AppTheme.NoActionBar")

    3. You should modify your other activities as follows:

      public class Mainactivity extends NavActivity
      {
      super.onCreate(savedInstanceState);
         LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
         //inflate your activity layout here!
         View contentView = inflater.inflate(R.layout.activity_main, null, false);
         drawer.addView(contentView, 0);
      }
      

    Note: the mainactivity will extend the action bar of the NavActivity, the NavActivity has a full functional action bar that will call the navigation drawer

    I hope it will work with you

提交回复
热议问题