Skip to content
This repository has been archived by the owner on Apr 30, 2020. It is now read-only.

Sections

Fabio Biola edited this page Mar 4, 2015 · 5 revisions

A section is a simple element of your navigation drawer list.

With sections, you should structure your app, because every section should be an app functionality.

There are two type of section at this time:

  • Text Section
  • Text and Icon Section

Every section could have a notifications number.
Every section have a target.

There are three different lists where you can add your section:

  • Top list (default list)
  • Bottom List
    It is a list used exclusively for About, Settings or other things like this.
  • Account List
    It is a list under the account list, used for addding accounts or other things.

NOTE If you add to the bottom list a section that doesn't mean that your section is pinned to the bottom.
See Material design guidelines > Settings and support for a complete explanation

Adding a section to the drawer

For adding a section, you have to instantiate it in your init() method:

MaterialSection section = newSection("Section 1", new FragmentIndex());

This is the simplest section you could use.
For others, there is a complete list:

// only text section, it opens an activity
public MaterialSection newSection(String title,Intent target)

// only text section, it opens a fragment
public MaterialSection newSection(String title,Fragment target)

// only text section, it calls target.onClick() method when section is clicked
public MaterialSection newSection(String title,MaterialSectionListener target)

// icon bitmap and text section, it opens an activity
public MaterialSection newSection(String title, Bitmap icon,Intent target)

// icon bitmap and text section, it opens a fragment
public MaterialSection newSection(String title, Bitmap icon,Fragment target)

// icon bitmap and text section, it calls target.onClick() method when section is clicked
public MaterialSection newSection(String title, Bitmap icon,MaterialSectionListener target)

// icon int resource and text section, it opens an activity
public MaterialSection newSection(String title, int icon,Intent target)

// icon int resource and text section, it opens a fragment
public MaterialSection newSection(String title, int icon,Fragment target)

// icon int resource and text section, it calls target.onClick() method when section is clicked
public MaterialSection newSection(String title, int icon,MaterialSectionListener target)

// icon drawable and text section, it opens an activity
public MaterialSection newSection(String title, Drawable icon, Intent target)

// icon drawable and text section, it opens a fragment
public MaterialSection newSection(String title, Drawable icon, Fragment target)

// icon drawable and text section, it calls target.onClick() method when section is clicked
public MaterialSection newSection(String title, Drawable icon, MaterialSectionListener target)

Then you have to add your section to the drawer list

// add section to the top list
public void addSection(MaterialSection section)

// add section to the bottom list
public void addBottomSection(MaterialSection section)

// add section to the account list
public void addAccountSection(MaterialSection section)

NOTE that the first section you added is opened when the activity starts, so it must have a Fragment as target.

Change Section Color

When a section that has a color is opened, the toolbar background color is setted to this value, and the status bar color is setted with the value of colorDark.
If a section with color is clicked the text color (into the drawer) is colored with his color. If the section has an icon, the icon have the color of the section.

mySection.setSectionColor(color,colorDark);

Set/get number notifications

int number = 4;
mySection.setNotifications(number);

int notifications = mySection.getNotifications();

Targets

The target is what the drawer open when the section is clicked. There are three types of target:

  • Fragment
  • Intent
  • Custom

Fragment

Is the default target.
When the section is clicked, the target fragment is replaced with the current one.

Intent

When the section is clicked, the library calls the startActivity() with your intent.

Custom

When the section is clicked, the library calls your MaterialSectionListener onClick.

NOTE: after the click, this type of section remains hightlinked.
You can override this behaviour calling the section.unSelect() in your listener.