Saturday 24 July 2021

Android Navigation Component with Drawer Layout and Dynamic Menu Items

So, here is what I want.

The top level data is structured like below :

Section 1 Title -> Section 1 Content (List)
Section 2 Title -> Section 2 Content (List)
.
.
.
Section N Title -> Section N Content (List)

I want to display the section titles in the side menu which opens when the hamburger is icon is selected and when a specific section is selected, the side menu closes and the content for that section is loaded in the screen under the action bar.

So, the relevant UI components to be used are : Toolbar, DrawerLayout (for Side Menu) and Fragment for loading the content in the center.

Now, I am trying to use the Navigation Components and get as much benefits of it as possible. The thing that I am unable to get to work is :

  1. Loading dynamic items in the side menu. The examples show using the android menu resources. I would like to use my own recycler view and load the menu dynamically.
  2. How to define the navGraph for a data structure like this. I tried to create an action from the ContentFragment to itself but I wasn't sure this was right because, there is no action inside it that takes the UI from one ContentFragment to another ContentFragment. It is a top level action from the side menu that loads a different ContentFragment.

Apart from the above 2 questions, I want to know if this is even a right candidate for using navigation components or is it better to use the traditional approach?



from Android Navigation Component with Drawer Layout and Dynamic Menu Items

No comments:

Post a Comment