Using a buttons invoves three steps: Adding prerequisie, Adding wiget and Adding behaviour.

Three stages of using a material design button

Prerequisie

  • Repository

The library that we require for using the Material Design Components are located in the Google Maven Repository, So we should make sure that it is added to the repository list in the Android Studio. For this purpose, open the project build.gradle file and add google() in the repositories section if it is not already there.

...
allprojects {
  repositories {
    google()
    jcenter()
  }
}
...
  • Libraries

To add the library to the project, open the application build.gradle file and  add the following lines if there are  not there

...
dependencies {
  ...
  def material_version = "1.1.0-beta01"
  implementation “com.google.android.material:material:$material_version”
  ...
}
...

You can visit the google maven repository at Google Maven to find the latest version 

  • Theme

Use the material design theme so that your UIs inherit all the styles available through this theme. For this purpose open the style.xml file and change the following line

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

to this line

<style name="AppTheme" parent="Theme.MaterialComponents.DayNight">

If for any reason you cannot change the theme, refer to this link for alternative approaches.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s