How to Display Navigation Drawer in all activities?

后端 未结 8 1260
刺人心
刺人心 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:10

    in onCreate of TutorialActivity don't call setContentView instead do this:

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        LayoutInflater inflater = (LayoutInflater) this
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View contentView = inflater.inflate(R.layout.help, null, false);
        mDrawer.addView(contentView, 0); 
    }
    

    make mDrawer in MainActivity protected. and in R.layout.activity_main_drawer just keep drawer tag and the element with gravity left(or right).

提交回复
热议问题