简体   繁体   中英

Use fragment as parent activity

I'm writing an android app which uses a drawer navigation in which the user can go to different activities. Inside the activities, the user can launch a new child-activity and can come back to the original one via up navigation in the AppBar.

Until now, I normally launched the new activities via an intent after they were chosen in the drawer menu. Then inside the chosen activity I created a new AppBar in onCreate();

However, I want to use the same Drawer for all Activities because I want the current activity, to be shaded in the menu and I also don't want to set up a new AppBar in many of the activites.

I've read that the common way to this, is to make a BaseActivity and a base_layout, which hosts the AppBar and the Activities as a Fragment. However, that's also not really suitable for me, since I can't declare styles in the manifest and upward navigation doesn't work.

How would you go about the problem?

If u want to make a navigation drawer that works for all fragment then
make a navigation drawer inside the main activity(This will work as a parent activity) and u can open fragment from that navigation drawer
Here is the tutorial
https://www.journaldev.com/9958/android-navigation-drawer-example-tutorial

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM