So i have a navigation drawer like so it has 3 buttons that go to 2 different fragments and the other button which goes to an Activity.
When I click one frag 1 my fragment opens up with the drawer still intact same goes for Frag 2 but when i click on the Activity 1 the Drawer disappears but i would like the drawer to continue in the activity as well. can this be done.
What you'd want to do (roughly) is
This can't be done.
The DrawerLayout
lives within your Activity
and the Fragments
that you switch to also live within the same Activity
. This is the reason why switching fragments will leave the drawer intact. It's because they both exist within the same Activity without any interference.
However, launching an Activity
is different. This is a completely different Activity
which has it's own layout.
You actually only have two options if you wish to continue using a Drawer for main navigation.
Remove the need for the second Activity
and change that to a Fragment
. This way, all your fragments will exist within the same parent Activity
so it'll use the same drawer that exists in that parent Activity.
Create an identical DrawerLayout
and NavigationView
in the second Activity. Call code to have the Drawer be opened when it's created. This way, although you're not really using the same Drawer, you're giving the illusion that it's still the same Drawer.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.