Material Design / Text / Themes

Material – Part 3

In the previous article we applied a colour scheme to our RSS reader app using the appcompat library. In this article we’ll look at styling our text and also take a look at CardView.

One of the less well-publicised aspects (in terms of Lollipop rather than Material design itself) of the Material themes in Lollipop and the appcompat library is the introduction of some pre-defined text styles. The idea behind these is that we can select the most appropriate text style from one of the pre-defined styles and a consistent text style is maintained across different apps. These styles are detailed in the Material Design Style reference.

Actually applying these text styles is simplicity itself. On Lollipop there are a number of TextAppearance styles in android.R.style.TextAppearance.Material.* and these correspond to the styles in the Material Style reference. Using appcompat is just as easy – we use the styles defined in R.style.TextAppearance.AppCompat.* instead:

We also need to do the same in res/layout/feed_detail.xml, but I won’t bother listing it here as the changes are much the same.

The next thing worth considering is using CardView within our layouts. CardView is a utility component which has been released in its own compatibility library and makes it very easy to include a Material cards in our apps. The cardview compatibility library defines a new CardView widget which essential has the same behaviour as FrameLayout (it actually subclasses FrameLayout) and will render a card-like outline.

As this is a compatibility library it will use the appropriate controls and features of the host OS – so on Lollipop the shadows will be rendered using the new algorithms which are baked in, but on pre-Lollipop devices drawables will be use to create the shadow effects. The best user experience will be on Lollipop which supports the native shadow drawing, but it still looks pretty good on older devices:

One point that Nick Butcher & Chris Banes made during their Papercraft talk at Droidcon London 2014 was not to over cardify apps – only use cards where they are appropriate. In this case, I do not feel that cards are appropriate for our ListView because these individual ListView items are essentially all the same kind of data. However, in the detail view he have a header section and the body containing the full article in a WebView and these sections are ideal for separating as cards.

Firstly we need to add the cardview library to our dependencies:

Then it is simply a case of wrapping the existing controls in CardView containers in the layout:

That’s all there is to it! This is how it looks on Lollipop:

CardView-Lollipop

And on Kitkat it also looks pretty good (there is a difference in the form-factor of the devices which accounts for the layout differences – a Nexus 9 for Lollipop and a Nexus 5 for Kitkat):

CardView-Kitkat

So we’ve actually achieved quite a lot in terms of converting our app to use Material design patterns without having to add a great deal of code in this article!

In the next article we’ll switch from looking at UI to how we can optimise things behind the scenes as an enabler to adding more Material goodness to the app.

The source code for this article is available here.

© 2014 – 2015, Mark Allison. All rights reserved.

CC BY-NC-SA 4.0 Material – Part 3 by Styling Android is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. Permissions beyond the scope of this license may be available at http://blog.stylingandroid.com/license-information.

Leave a Reply

Your email address will not be published. Required fields are marked *