Add Navigation Drawer to an existing activity

前端 未结 3 2025
南笙
南笙 2021-02-01 03:05

I have an app I am writing and it is already contains a lot of code, I decided I want to add a navigation drawer to the main activity toolbar but I don\'t know how to do it with

3条回答
  •  时光说笑
    2021-02-01 03:42

    I've tried the MaterialDrawer library, as suggested by @yury-dombaev and I have to admit it's far easier to implement than the official Navigation Drawer.

    It's possible to implement either with Android X dependencies or with the normal ones.

    In my case, since I have the normal ones, I've to stick with the MaterialDrawer 6.0.9v. Although there's a migration guide that I'll give a look.

    To implement the library within your current activity do the following:

    1. Add the dependencies in your app build.gradle as explained in Setup 1 of the v 6.0.9 of the library: https://github.com/mikepenz/MaterialDrawer/tree/v6.0.9
    2. Add your drawer in the onCreate() method of your Activity: new DrawerBuilder().withActivity(this).build();.
    3. Now you've got a basic (and useless) lateral menu. So it's time you continue reading the Material Drawer documentation and add menu elements :)

提交回复
热议问题