Same Navigation Drawer in different Activities

前端 未结 12 1440
执念已碎
执念已碎 2020-11-22 04:24

I made a working navigation drawer like it\'s shown in the tutorial on the developer.android.com website. But now, I want to use one Navigation Drawer, i created in the Navi

12条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-22 05:26

    I've found the best implementation. It's in the Google I/O 2014 app.

    They use the same approach as Kevin's. If you can abstract yourself from all unneeded stuff in I/O app, you could extract everything you need and it is assured by Google that it's a correct usage of navigation drawer pattern. Each activity optionally has a DrawerLayout as its main layout. The interesting part is how the navigation to other screens is done. It is implemented in BaseActivity like this:

    private void goToNavDrawerItem(int item) {
            Intent intent;
            switch (item) {
                case NAVDRAWER_ITEM_MY_SCHEDULE:
                    intent = new Intent(this, MyScheduleActivity.class);
                    startActivity(intent);
                    finish();
                    break;
    

    This differs from the common way of replacing current fragment by a fragment transaction. But the user doesn't spot a visual difference.

提交回复
热议问题