Java tutorial
//package com.java2s; //License from project: Open Source License import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.graphics.drawable.StateListDrawable; public class Main { public static StateListDrawable selector(int color) { StateListDrawable drawable = new StateListDrawable(); drawable.addState(new int[] { android.R.attr.state_pressed }, getColorDrawable(color)); drawable.addState(new int[] { android.R.attr.state_focused }, getColorDrawable(color)); drawable.addState(new int[] { android.R.attr.state_selected }, getColorDrawable(color)); drawable.addState(new int[] { android.R.attr.state_activated }, getColorDrawable(color)); return drawable; } private static Drawable getColorDrawable(int colorCode) { return new ColorDrawable(colorCode); } }