Design Support Library - kmolo/android_guides GitHub Wiki

Overview

At their I/O 2015 conference, Google announced a new design support library, which helps bring a lot of material design components including a navigation drawer view, floating labels, floating action buttons, snackbars, and a new framework to tie motion and scroll events. The library is supported for Android version 2.1 and higher.

Features

The support design library has the following key features:

  1. FloatingActionButton - A round button at the bottom right denoting a primary action on your interface. Promoting key actions within a modern material design app.
  2. TabLayout - An easier way to put tabs around a ViewPager which acts as sliding tabs between fragments within an app.
  3. NavigationView - An easier way to provide a modern navigation drawer from the left with a header and a series of navigation items.
  4. SnackBar - Shown on the bottom of the screen and contains text with an optional single action. They automatically time out after the given time length by animating off the screen.
  5. TextInputLayout - Float the hint above any text field as the user is entering information.
  6. CoordinatorLayout - Provides an additional level of control over scroll and touch events between child views.
    • AppBarLayout allows your toolbar and other views to react to scroll events.
    • CollapsingToolbarLayout extend this to allow the toolbar to collapse as the user scrolls through a view.
  7. PercentRelativeLayout and PercentFrameLayout to enable views to occupy percentage-based dimensions.

Setup

Make sure that you have at least the Android Gradle plugin v1.2.3 supported. There are several issues with using older versions including some support library widgets fail to render correctly (see issue).

    dependencies {
        classpath 'com.android.tools.build:gradle:1.2.3'
    }

There is a new support design library that must be included. This library also depends on updated versions of the AppCompat library to be included. If you are not currently using this library, check out this migration guide. In addition, make sure these versions have been updated.

dependencies {
    compile 'com.android.support:appcompat-v7:22.2.1'
    compile 'com.android.support:design:22.2.1'
}

If you are using the RecyclerView, CardView, or any other support v7 related libraries you should also upgrade the versions. The RecyclerView for instance has features that are used with this new design support library.

dependencies {
    compile 'com.android.support:recyclerview-v7:22.2.1'
}

To add the percent support library, you need to add this statement:

dependencies {
    compile 'com.android.support:percent:22.2.0'
}

You normally need to open the SDK Manager and make sure to download the Android Support Repository as well as the latest Android Support Library. However, Android Studio will also show at the bottom any missing libraries and you can click on the Install repository and sync project. The process will only succeed if you specify a valid library and version, but it enables you to upgrade without needing to open the SDK Manager.

If you are using any type of continuous build system and need to help automate downloading of updates to the support library, you can use Jake Wharton's SDK Manager to download the packages for you.

Sample Code

If you want to see how to use the various components, check out this sample code. For an example of the percent support library, see this sample code.

Official Source Code

The source code for this library can be found here. For instance, if you are curious about what styles can be overridden for the different components, see this link.

Currently, the source code for CoordinatorLayout and AppBarLayout do not appear to be publicly available. Assuming you are using Android Studio v1.2 or higher, the decompiler code should enable you to understand better what's happening.

References