Start a Project

Using Material components in Android

In this blog, we will learn about using material components in Android.

With the release of new Material components library, you get a hot box of powers for creating your own user interaction components easily.

But these features were already present in the design support library. So why should I use this new component Library?

Well, the answer to this can be seen in much details over here. But what I found exciting was a whole list of built-in components and their styles that can change the whole layout of your components efficiently. Moreover, you can now use these :

And the UI components that now you can create and style amounts to a huge list.

But what we currently want to focus on is how you can use this in your android project/ application.

What official document recommends is you migrate to “androidx” and start coding into it for easy implementation. if you want to do that then you will need to have an android studio 3.2 ( which currently is in its canary build Stages).

But don’t worry this does not mean that you cannot use this component library.

You can definitely use this on android studio 3.1 as well. All you need to do is follow their documentation ( which i find personally hard) or  read along :

APPROACHES

APPROACH #1:

Start using androidx and for this, all you need to do is read carefully this page and follow along.

APPROACH #2:

Update your dependencies and other requirements as mentioned below :

  1. Check you are using the correct compile SdkVersion in your app level build.gradle file ( compileSdkVersion 28).
  2. Check you have correct design dependencies in your project.( 28.0.0-alpha3)
  3. Now in your styles.xml file, you need to change the default theme to a material based theme

You are now Good to go. After this, all you need to do is set the style of the component you are going to use (either through style attribute of the Layout element, if you just wish to change the style of a particular element or through the styles.xml for global settings across your application).

SAMPLE CODE

app-level “build.gradle” file :

 

styles.xml File :

Layout sample file :

 

Hope this helps you in getting an idea of how easily you can start using the new material components in your android applications.

Keep Coding, Keep Sharing 🙂

 

 

 

Exit mobile version