Sapan Diwakar

Software developer

Follow me on Twitter Check out my code on GitHub View some of my designs on Dribbble Take a look at my Linked In profile

Using Subtle Patterns in Android apps

Subtle Patterns has an amazing collection collection of high quality patterns for use in websites and applications. I had used the patterns in a few iOS apps and its really easy and looks great. Here's how you would set a pattern from subtle pattern to the background of a view in iOS.

[self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"my-subtle-bg"]]];

Unlike iOS, using these patterns in Android is not straightforward. You can't just put it as a drawable and set the background for the view because the default behavior for background images in android is stretching rather than tiling. To use these, we have to define a Bitmap Drawable using the pattern as the src and tileMode as repeat. First copy the pattern (e.g. my_suble_pattern.png) in your drawable-mdpi and then create a bitmap (e.g. my_subtle_pattern_tiled.xml) in drawable.

<?xml version="1.0" encoding="utf-8"?>  
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"  
  android:src="@drawable/my_suble_pattern"
  android:tileMode="repeat" />

Now you can use the tiled pattern as the background for any view like

android:background="@drawable/my_subtle_pattern_tiled"