Material Design Support Library Tutorial – Part 2

Material Design Support Library Tutorial – Part 2

In the first article about Material Design Support Library I was show you how to use Android Design Support Library to implement SnackBar, Floating Action Button, TextInputLayout and Navigation View. In this article, I will show you how to use Android Design Support Library to implement more Material components.

  • Tab Layout
  • Coordinator Layout
  • ToolBar and CollapsingToolBar Layout

Tab Layout

Tabs make it easy to explore and switch between different views or functional aspects of an app or to browse categorized data sets.


To implement TabLayout to your apps, the firs you must add TabLayout widget into your layout file like the code below.

  android:background="#2196F3" />
    app:layout_scrollFlags="scroll|enterAlways" />

Where should we place TabLayout? According to Android Application UX Guideline, Tab should be place on top of the screen not the bottom. So we will place it below ToolBar. TabLayout have some attributes that you should know.

  • app:tabMode you can set it as fixed or scrollable. If you want to display every tab on the screen, set it as fixed. It good for a small number of tabs. But you have a many tabs in your screen, you should set attribute as scrollable to be displayed nicely.
  • app:tabGravity If you want to place all tabs in the center of the screen, you should set it as center. When you set attribute as fill, all tabs distributed in available space.


After add TabLayout in your layout file, you must add some tabs with java code.

 TabLayout tabLayout = (TabLayout) findViewById(;
 tabLayout.addTab(tabLayout.newTab().setText("Tab 1"));
 tabLayout.addTab(tabLayout.newTab().setText("Tab 2"));
 tabLayout.addTab(tabLayout.newTab().setText("Tab 3"));
 tabLayout.addTab(tabLayout.newTab().setText("Tab 4"));
 tabLayout.addTab(tabLayout.newTab().setText("Tab 5"));

Coordinator Layout

According, CoordinatorLayout is a super-powered FrameLayout.

CoordinatorLayout is intended for two primary use cases:

  • As a top-level application decor or chrome layout
  • As a container for a specific interaction with one or more child views

By specifying Behaviors for child views of a CoordinatorLayout you can provide many different interactions within a single parent and those views can also interact with one another. View classes can specify a default behavior when used as a child of a CoordinatorLayout using the DefaultBehavior annotation.

Behaviors may be used to implement a variety of interactions and additional layout modifications ranging from sliding drawers and panels to swipe-dismissable elements and buttons that stick to other elements as they move and animate.

Children of a CoordinatorLayout may have an anchor. This view id must correspond to an arbitrary descendant of the CoordinatorLayout, but it may not be the anchored child itself or a descendant of the anchored child. This can be used to place floating views relative to other arbitrary content panes.

Now, I will show you how to add CoordinatorLayout into your apps. Add CoordinatorLayout into your layout file as root container like code below.

    app:rippleColor="#FF80AB" />

Done. FloatingActionButton automatically moves upward as the snackbar animates in and returns to its position when the snackbar hides.