One thing that excites me each time a new Android SDK comes out is the advances in the Android graphics subsystem. With its material design specification and more fluid transition engine, Android 5.0 is no slacker. One feature introduced in API 21 is the concept of drawable tinting.

Drawable tinting makes so much sense in a small form factor device like Android that I’m surprised the Google team didn’t get around to it sooner. It allows for the definition of a common color theme across components, without requiring lots of custom components to be packed with your APK; more than that, it allows dynamic styling that can be brand or content aware.

The demo I concocted below utilizes the new setTint() method to randomly flash the light on the top of the tree different colors. You can follow along or download and import the entire project directly into Android Studio.

1. Create a new project in Android Studio. You must target a minimum of API 21 (Lollipop) to get access to the new API.

2. To keep things simple, edit your project manifest to force portrait-only orientation.


android:label="@string/app_name" >

3. Add two images to your /res/drawable folder: one for your tree (Figure A) and one for the star (Figure B). The tree image is green, but the star one is gray scale so it absorbs the most possible color when the tint is applied.

Figure A

Figure B

4. In the /res/layout folder, create a linear layout that places the star above the tree via two stacked image views.


5. Create a handler and an associated runnable in the /Java/ file that randomly applies a new tint every half a second.
package com.authorwjf.colortintedbitmaps;

import android.os.Bundle;
import android.os.Handler;
import android.widget.ImageView;

import java.util.Random;

public class MainActivity extends Activity {

private Handler h = new Handler();
private int[] xmasLights = new int[] {Color.RED, Color.BLUE, Color.GREEN, Color.YELLOW};

protected void onCreate(Bundle savedInstanceState) {
h.postDelayed(r, 500);

private Runnable r = new Runnable() {
public void run() {
ImageView iv = (ImageView) findViewById(;
Random gen = new Random();
int randomColor = gen.nextInt(xmasLights.length);
h.postDelayed(r, 500);

Go ahead and run the code on an emulator or device (Figure C) — remember that it must be running Lollipop.

Figure C

How easy was that? The use case here is very simple, but I look forward to diving into all the new graphic APIs that Android 5.0 has to offer in 2015!