Introduction to Upcoming AndroidX with Material Components

What is AndroidX?

AndroidX (Android Extension library) is the new era of Android Support library which every Android Developer were using since 7+ years. AndroidX supports newer OS features on older versions of Android along with newer device-specific UX, new features under Android KTX, debugging, testing. To keep in mind for smaller and more focused packages, AndroidX redesigns the packages structure such that both the names of Architecture Components and support libraries are simplified. This should help make clear that which dependencies should be included in the APK.

Now the biggest question might arise in every developers’ mind that there are components and packages named “v7” when the minimal SDK level we support is 14! What about that? It’s worth making clear that to work across different versions of Android is to understand the division between APIs that are bundled with the platform and which are static libraries for developers. So developers, it’s time to say “Hello World” to AndroidX.

Migrate from the Support version to AndroidX .

In Android Studio do Refactor -> Refactor to AndroidX.. .This feature is available on Android Studio Canary 14 for app targeting Android P. Android Studio will update that library directly to reference androidx.

To implement high quality application in lesser time, it would be easier for developers to make above changes of AndroidX, but changes by AndroidX will have an impact on existing code and migration takes time, so for that reason Google is also giving parallel updates to android.support for P preview SDK timeframe which will continue the 28.0.0 as a final feature release as android.support.

AndroidX Refactoring

Now to create a new project using androidx-packaged dependency, your new project needs to target API level 28, and you will need to add the following lines to your gradle.properties:

Some of the package changes from android.support(28.0.0-alpha1) to androidx(1.0.0-alpha1) will look like this: (This might have minor change during alpha phase)

For support library -> android.support.** to androidx.@ ,

For dataBinding library -> android.databinding.** to androidx.databinding.@

For design library -> android.design.** to com.google.android.material.@

For Room database under
Architectural components -> android.arch.persistence.room.** to androidx.room.@

For More Refactoring Refer this

Material Components

All the new announcements made in Google I/O 2018 make a huge change in terms of enhanced with expanded design guidance , tools geared toward solving the lags between design and development, and customisable UI components for not only Android but also for iOS, Web and Flutter. So drop-in replacement of Design Library as a Material Components in 28.0.0-alpha1 or AndroidX and to help you build beautiful digital experiences even faster will be huge change in the world of design and development.

These are few steps to setup environment for material design:

  • Use Android Studio Canary 14 for app targeting Android P for support-v4:28.0.0-alpha1’ or AndroidX.
  • gradle-wrapper.properties
  • Update build.gradle(project-level)
  • Update build.gradle (Module level)

Under dependency tag

  • If you are using support lib 28.0.0-alpha1
    build.gradle (module level)
  • If you are using AndroidX then you will replace api ‘com.android.support:design:28.0.0-alpha1’ with implementation ‘androidx.appcompat:appcompat:1.0.0-beta01′ and implementation ‘com.android.support:support-v4:28.0.0-alpha1’ with implementation ‘com.google.android.material:material:1.0.0-beta01’.
    build.gradle (module level)
  • Update App theme
    style.xml

1. Material TextinputEditText

To create a material text field, add a TextInputLayout to your XML layout and a TextInputEditText as a direct child.

androidx-image1

activity_login.xml

style.xml

To make a outline textField , put a style like

2. Material Button

androidx-image2

Here, you can use one of these style for Material Button for ex:

Above code will set primaryColor as backgroundColor

This will set transparent background to your button.

Another best thing about Material Components are whole material is dynamic. Now, developers don’t need to make a drawable to make button customise. We directly can set cornerRadius, backgroundTint, set icon, iconTint, iconPadding from xml as well as default get Built-in touch feedback (called MDC Ripple) and elevation.

activity_login.xml

NOTE: You can access all the examples in our GITHUB link

3. Bottom AppBar And FAB

BottomAppBar is an evolution and one of the defining features from standard Material guidance. It puts more focus on features, increases engagement, and visually anchors the UI.

androidx-image3

act_bottom_appbar_behaviour.xml

BottomAppbarBehaviour.kt

Above code will set menu to the bottomAppbar.

activity_bottom_app_behaviour.xml

bottom_appbar_menu_primary.xml

4. BackDrop Menu

Backdrop is one of the newest features in Material design which is the furthest back surface of an app, appearing behind all other content and components. Backdrop Menu is composed of two surfaces: a back layer (which displays actions and filters) and a front layer (which displays content). This can be used to display interactive information and actions which is navigation or content filters.

androidx-image4

First of all Add Menu:

layout_backdrop.xml

Add this layout file to the layout file of activity

activity_backdrop.xml

Backdrop style will look like:

styles.xml

Below section that is responsible for setting up the toolbar.

BackDropActivity.kt

Add Motion
The type of motion used must should be eye catching and small because it is applied to repeated actions. The motion is the shape in front moving straight down.We can set this click listener with AccelerateDecelerateInterpolator() and icons for the open and close menu in BackDropActivity.kt onCreate() to provide Tweak motion of front layer.

BackDropActivity.xml

5. Material Chips

androidx-image5

Chip is nothing but a rounded button that consist of a label, an optional chip icon and optional close button. To represent it as a semantic entity text field can replace text with chipDrawable.

There are some updated material style which are updated to the latest Material theme that is as below
-> Entry chips :

This style contains optional chip icon, optional close icon and optionally checkable.

->Filter chips

This contains an optional chip icon, an optional close icon but difference is always checkable.

->Choice chips

This chip is to help users to make a single selection from finite set of options that contains optional chip icon and always checkable.

->Action chips

Chip with updated material theme will give you updated Material Styles to your chips by default.

Conclusion

So Devs!, These are few components of material design using that you can create attractive and beautiful digital experience. You must try your hands on updated Material Components.

To know more about Material design introduced in Google I/O 2018 refer this.

mm

Pooja Shah Android Developer

I am Pooja Shah, enthusiastic android developer at Yudiz Solution Pvt Ltd- a mobile app development company .I am passionate about developing my abilities in new technology and I enjoy socializing.

Comments are closed.

Top