Android Navigation Drawer (calling activities) with AbstractMainActivity

半城伤御伤魂 提交于 2019-11-30 09:43:41

I'm also trying to figure out how to do this.

I've seen a very good tutorial that does exactly what you want here. The idea is to create an abstract activity class AbstractNavDrawerActivity that all activities with drawers will inherit from. This class uses a NavDrawerActivityConfiguration bean class that holds all the information about the nav drawer including the layout that needs to be inflated

Another approach would be creating a NavDrawerUtil class where you would put static methods that interact with the nav drawer. You would then call these methods from each activity as you need.

The second approach gives you more flexibility and you don't have to worry about order of layout inflations and such but I think it's a less clean solution than the first one with the AbstractNavDrawerActivity that all activities with nav drawer inherit from like you suggested.

What I've done in previous apps is have a sliding menu built as a function call in the abstract activity. When you set up a new Activity extending the abstract activity, you perform the function call in the onCreate(). I'm currently working on a similar implementation using the Navigation Drawer instead, so I'm not quite sure if it works yet, but it might be a good place for you to start. All your Activities that will call the Navigation Drawer will need to have a DrawerLayout as the top-level layout element.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!