Java tutorial
//package com.java2s; import android.graphics.Bitmap; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.StateListDrawable; public class Main { public static StateListDrawable bgColorDrawableSelector(Bitmap nomal, Bitmap focus) { BitmapDrawable nomalBitmap = new BitmapDrawable(nomal); BitmapDrawable focusBitmap = new BitmapDrawable(focus); StateListDrawable selector = new StateListDrawable(); selector.addState(new int[] { android.R.attr.state_pressed }, focusBitmap); selector.addState(new int[] { android.R.attr.state_selected }, focusBitmap); selector.addState(new int[] { android.R.attr.state_focused }, focusBitmap); selector.addState(new int[] {}, nomalBitmap); return selector; } }