Different toolbar for fragments and Navigation Drawer

后端 未结 5 1793
花落未央
花落未央 2020-12-16 01:35

Please, explain to me... I have Navigation Drawer in my Activity and it syncs with Toolbar (like ActionBar). Activity has few fragment

5条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-16 01:42

    You can access main DrawerLayout from each Fragment just like the following code:

    AppCompatActivity actionBar = (AppCompatActivity) getActivity();
    actionBar.setSupportActionBar(toolbar);
    
    DrawerLayout drawer = (DrawerLayout) actionBar.findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                getActivity(), drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();
    

提交回复
热议问题