How to Migrate to Material Components (MDC)

Material Components (MDC) is built by developers at Google (separate from the Android team) with intentions of helping developers build Material Design in their web and mobile-based apps. This is the next iteration of Material Design released in 2014.

Follow the steps mentioned below to migrate the app to use the Material Design Components instead of AppCompat or default UI components.

1) Add the Material Components dependency to the module level build.gradle file.

implementation 'com.google.android.material:material:1.1.0-alpha02'

2) In the styles.xml Replace AppCompat with MaterialComponents. If you performed the action successfully then your base application theme will look like this.

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>


login-mdc-material-design-material-components

Points To Remember:

1) Adding the dependency alone won't let you add the Material Components to the layouts, you need to change the theme in the styles.xml to use Material Components theme otherwise the app crashes with an IllegalArgumentException.

Caused by: java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant).

2) If you are currently using AppCompat support libraries, you need to migrate to androidx dependencies. Combined use of com.android.support and com.google.android.material will throw Manifest merger failed as the Material Components internally use androidx packages.

3) compileSdkVersion needs to be set to a minimum of 28 to avoid getting resource linking failed error since resources like dialogCornerRadius, fontVariationSettings and ttcIndex are missing.

Popular posts from this blog

Arithmetic Operations in Tensorflow

How to Create Facebook App

How to Create Facebook Page