How to set up your Android app project to use Material Design with AppCompat

AppCompat v21.+’s Theme.AppCompat extends Theme.Base.AppCompat which extends Theme.Platform.AppCompat which extends android:Theme.Material on 21+ devices (i.e. Android 5.0 Lollipop) so you only need to extend Theme.AppCompat to use Material theme if you are using the AppCompat v21 (or above) library.

First add compile ‘’ to the dependancies section of your build.gradle file.

apply plugin: ''
android {
compileSdkVersion 21
buildToolsVersion "21.1.1"
defaultConfig {
applicationId ""
minSdkVersion 9
targetSdkVersion 21
versionCode 1
versionName "1.0"
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), ''
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile ''
view raw build.gradle hosted with ❤ by GitHub

Edit your styles.xml to add the style AppTheme.Base and have AppTheme extend AppTheme.Base. For example:

<!-- Base application theme. -->
<style name="AppTheme" parent="AppTheme.Base"/>
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<!-- colorPrimary is used for the default action bar background -->
<item name="colorPrimary">@color/colorPrimary</item>
<!-- colorPrimaryDark is used for the status bar -->
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<!-- colorAccent is used as the default value for colorControlActivated
which is used to tint widgets -->
<item name="colorAccent">@color/colorAccent</item>
<!-- You can also set colorControlNormal, colorControlActivated
colorControlHighlight & colorSwitchThumbNormal. -->
view raw styles.xml hosted with ❤ by GitHub

You don’t have to call it AppTheme.Base. You can call it whatever you want. You’ll need to change @color/colorPrimary, @color/colorPrimaryDark and @color/colorAccent to your own colour preferences in your colors.xml file.

There’s a great Github Gist of Material Design Colours at

Next create a values-21 folder in the res folder if you don’t already have one. Then create or edit styles.xml in your res/values-v21 folder. AppTheme should extend AppTheme.Base instead of android:Theme.Material.Light. For example:

<?xml version="1.0" encoding="utf-8"?>
<style name="AppTheme" parent="AppTheme.Base">
<!-- Customize your theme using Material Design here. -->
view raw styles21.xml hosted with ❤ by GitHub

If you extend android:Theme.Material.Light instead of AppTheme.Base then you’ll get an “IllegalStateException:You need to use a Theme.AppCompat theme (or descendant) with this activity” error.

Now you just need to set the theme as AppTheme in the AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=""
package="" >
android:theme="@style/AppTheme" >
android:label="@string/app_name" >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
view raw AndroidManifest.xml hosted with ❤ by GitHub