Material design is a comprehensive guide for visual, motion, and interaction design across platforms and devices. You can find more information, design guidelines about Material Design here: http://www.google.com/design/spec/material-design/introduction.html#introduction-principles
Luckily, Google also provides support library – AppCompat v21 – to allow us to apply Material Design on older Android versions.
A – AppCompat v21 Library
AppCompat v21 library supports following material design features:
- Provide Material Design style for some system widgets (EditText, Spinner, CheckBox, RadioButton, SwitchCompat, CheckedTextView) when using AppCompat theme
- Customize theme colour palette
- CardView – a new View in Android 5.0
- RecyclerView – a new View in Android 5.0 used to display data collection
- Palette – and utility class to extract prominent colours from image
B – Apply Material Design to Pre-Lollipop Devices using AppCompat v21
1 – Set Up
Add following dependencies to Graddle build file:
2 – Apply Material Theme
Opent styles.xml and make your AppTheme inherit from Theme.AppCompat.
You can also customize theme colour palette here
Parallelly, you should create a specific styles.xml file for Android 5.0 (in values-v21 folder), to be able to use all the Material Design features:
FYI about the colour attributes:
- colorPrimary: the primary colour of your app, will be applied to the app bar
- colorPrimaryDark: will be applied to the status bar and contextual app bars
- colorAccent: will be applied to some theme UI controls like Checkboxes, RadioButton, EditText,…
3 – Demo using supported system widgets
Now, your project is ready to use Material Design theme.
Here, I added some common views to the activity for a visual demo only:
C – Download Source Code for Apply Material Design to Pre-Lollipop Devices using AppCompat v21
In next post, I’ll introduce about 2 new Views in Android 5.0: CardView and RecyclerView.
This post is licensed under CC BY 4.0
by the author.