Intro Material Design & Support Libraries

Hafiz Waleed Hussain
U Want To Learn
Published in
6 min readJun 28, 2015

Hello Guys. In these days I am getting lot of questions from my team members and from friends about Material Design and Support libraries. Mostly are confused what they are like v4, v7, v13, design support library, annotation library and more. So I decided to elaborate all these things and also show them how Google Developer Team doing a lot of good work for us so we can make awesome apps.

Motivation:
OK first and most important thing there is a possibility this post will be long but I promise with you guys that is not boring if you feel that will be a long and theoretical post then I have one suggestion for you guys. Please scroll down all post with out reading and see all images so you easily know after reading this post your confusions will be gone and you are updated with Android. :) One more important thing only enjoy text and images and do not take tension about code. I will give you all codes in separate posts. :)

Introduction:
As we know Google updating Android OS very rapidly and those who has Google Android Devices they will get updates very early but the biggest issue of Android is, that is an Open Source. So there are many other vendors which are using Android like Samsung, HTC and many more. These vendors taking time to give update of OS. So these users are not able to enjoy the new features and experiences. In my opinion Google uses a this approach to make Support libraries. Every Android user can get the enjoyment of new features if there vendor did not update the OS but developer added library into there application then any old OS user can enjoy the latest features in its device.

Support Libraries:
Currently available support libraries are:

  • v4 support library
  • v7 support libraries
  • v8 support library
  • v13 support library
  • v17 support library
  • Annotations support library
  • Design support library
  • Multidex Support Library

Now I am going to define each and every library one by one but before that only you need to know what are these version numbers. So v4 means this library compatible with Android API level 4 or Android 1.6. For more clearance like we know Android launched Fragments in Android 3.0 but if I want to use that below this API like I have minimum SDK version 1.6 then I will add v4 library and now I can use that feature in Android 1.6. I think now that ambiguity is clear.

V4 Support Library:
As I already mention this library compatible with Android 1.6. Components which are available in this library you can check on
android developer website.

V7 Support Libraries:
V7 mean our application min version support will be API level 7 or Android 2.1 then this library will be compatible and give us the awesome features which are basically given in advance OS or API levels. There are more then one libraries which are available in V7 version. So I will discuss these libraries one by one.

V7 AppCompatLibrary:
Basically Google released first this library with name ActionBarCompat library in which they give the Action Bar feature to older version. Since then ActionBarCompat library renamed with AppCompatLibrary. If you want to add this library in Eclipse then you need to add V4 because that is dependent on this and if you add V7AppCompatLibrary in Android Studio then Gradle automatically manage that. Now its time to see what type of benefits we can get from this library.

1.Themes:
Without App Compat Library:

Now adding AppCompatLibrary:

After Adding AppCompat:

2. Material Color Palette:
Now we can use material color palette in Android 2.2 and above as shown below.

Code snippet:

3. AlertDialog:

Code Snippet:

4. ActionBar:

Code Snippet:

5. Toolbar:
Now in Android 5.0 we have a new widget with name Toolbar. Basically that is a
replacement of Action Bar. That is available in AppCompatLibrary and Toolbar is more flexible then Action Bar.

Code Snippet:
Very simple first open your style file and change Theme as shown below.

Next add Toolbar in your layout as we use Views and ViewGroups.

Now in Activity you need to set Toolbar as Action Bar.

Complete but I want to show you some more things about Toolbar. As we know we cab use Action Bar back to button to move Parent Activity. We can use same functionality in Toolbar.

Code Snippet:

Now I am going to customizing our Toolbar so you can easily know how much Toolbar is flexible then Action Bar.

Code Snippet:

V7 CardView Library:
CardView launched with Lollipop but that is also available as a support library and it is compatible up to API Level 7. CardView is a vary basic block in material design.

Now there I use 2 CardViews. In first I use some builtin properties of CardView to design differently from the second one.Code Snippet:

There are many things we can do with CardView to make our App user experience awesome. Now I am going to next libraries and those who want to learn more about CardView for them I have a good news. I have a plan to publish more posts on Animation, RecyclerView and a complete app of Material design. So I will use CardView in these posts and you easily learn more about this widget.

V7 GridLayout Library:
GridLayout also available in support library. I feel that contain lot of things so I will publish separate post for this library.

V7 RecycleView Library:
RecycleView basically replaces a ListView. It is a very power full and lightweight in comparison with ListView. For RecycleView I have a plan to publish a separate post.

V7 Palette Library:
This library help us to extract color from image on run time. Here I am giving one example in which we have a one ImageView with color image and one FrameLayout which has a default background color Black. So as we run app the FrameLayout background color will change with the ImageView bitmap color. Which I extract by using Palette.

Code Snippet:

V8 Support Library:
This library compatible with Android 2.2. Components which are available in this library you can check on
android developer website.

V13 Support Library:
This library compatible with Android 3.2. Components which are available in this library you can check on
android developer website.

V17 Support Library:
Components which are available in this library you can check on android developer website.

Annotations Support Library:
Annotations in my opinion are awesome. Here I am giving a simple example, as we know enums are not good according to android doc and not recommended due to performance issues. So we can use this annotation library to use integers but implement as type safe like enums.

Now as you see there are some compile time errors. Because we restrict our parameter and return type by using Annotation. So IDE is saying parameter and return type will be Move.

Now all compile time errors gone. One more thing if you see I use a RetentionPolicy.SOURCE so its mean that annotation only work on compile time as we run our app after that will be consider simple integer constants. If you want to explore more this annotation you can check on tools.android.com.

Design Support Library:
This library support adding material design components and patterns to apps. I am excited to tell you about this library components. But I feel this library has a long list of components and also our post already very long. So I decided I will publish a separate post for Design Support Library.

Now last thing how we can add these libraries in Android Studio. So there are two methods.
1. Open builde.gradle of app module and paste library name in class dependencies as shown below.

2. File — Project Structure — Dependencies — Library Dependency

I hope you enjoy this post. All of your ambiguities removed from your brain and I think now you are confident to use these libraries and make awesome Android apps for users.
I will launch other posts as early as possible which I mention in this post like Design Library, RecycleView etc

--

--