Java tutorial
//package com.java2s; import android.content.Context; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.graphics.drawable.StateListDrawable; public class Main { public static Drawable getSelectedStateDrawableByResColor(Context context, int normalcolor_id, int selectedcolor_id) { // StateListDrawable drawable = new StateListDrawable(); // drawable.addState(new int[]{- android.R.attr.state_selected}, new // ColorDrawable( context.getResources().getColor(normalcolor_id))); // drawable.addState(new int[]{ android.R.attr.state_selected}, new // ColorDrawable( context.getResources().getColor(selectedcolor_id))); Drawable normal = new ColorDrawable(context.getResources().getColor(normalcolor_id)); Drawable selected = new ColorDrawable(context.getResources().getColor(selectedcolor_id)); return getSelectedStateDrawable(normal, selected); } public static Drawable getSelectedStateDrawable(Drawable normal, Drawable selected) { StateListDrawable drawable = new StateListDrawable(); drawable.addState(new int[] { -android.R.attr.state_selected }, normal); drawable.addState(new int[] { android.R.attr.state_selected }, selected); return drawable; } }