18.3K Followers
·
Follow

Image for post
Image for post

Here’s why

Your app exists alongside other apps installed on a user’s phone. We therefore recommend that applications follow the Material Design guidelines to ensure that apps operate consistently, that patterns learned in one app can be used in another.

Android users expect your app to look and behave in a way that’s consistent with the platform. You should follow material design guidelines for visual and navigation patterns… — d.android.com/design

To implement this, use the Material Design Components (MDC) library. This blog post outlines the many benefits of using MDC, explaining why it’s our recommended solution.

Widgets

Image for post
Image for post

MDC provides styled versions of standard widgets making it easy to implement Material styling. For example Material offers styled versions of Buttons, Toolbars, CheckBoxes and more. If you use a MaterialComponents theme, then Material widgets will be instantiated instead of the stock components when you inflate a layout (by MDC’s View Inflater) so it’s easy to achieve Material styling without having to make large updates to your…


Image for post
Image for post
Illustration by Virginia Poltrack

In previous articles in this series on Android styling, we’ve looked at the difference between styles and themes, talked about the benefits of using themes and theme attributes and highlighted some common attributes to use.

Today we’ll focus on actually using themes, how they are applied to your app and the implications for how you build them.

Scope

In a previous article we stated:

A Theme is accessed as a property of a Context and can be obtained from any object which is or has a context e.g. Activity, View or ViewGroup. These objects exist in a tree, where an Activity contains ViewGroups which contain Views etc. Specifying a theme at any level of this tree cascades to descendent nodes e.g. …


Image for post
Image for post
Illustration by Virginia Poltrack

Theme attribute all the things

In the previous posts in this series on Android styling, we looked at the difference between themes and styles and why it’s a good idea to factor out things that you wish to vary by theme and common theme attributes to use:

This enables us to create fewer layouts or styles, isolating changes within a theme. In practice, you largely want to vary colors by theme and as such you should always* refer to colors via theme attributes.

Always* refer to colors via theme attributes

That means you can consider code like this to be a smell:

Instead you should refer to a theme attribute, allowing you to vary the color by theme, for example, providing a different value in dark…

About

Nick Butcher

Android designer + developer @ Google

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store