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.
MDC provides styled versions of standard widgets making it easy to implement Material styling. For example Material offers styled versions of
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…
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.
In a previous article we stated:
Themeis accessed as a property of a
Contextand can be obtained from any object which is or has a context e.g.
ViewGroup. These objects exist in a tree, where an
ViewGroups which contain
Views etc. Specifying a theme at any level of this tree cascades to descendent nodes e.g. …
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…