Android examples for Graphics:State List Drawable
get Pressed Selector as StateListDrawable
//package com.java2s; import android.content.Context; import android.graphics.drawable.Drawable; import android.graphics.drawable.StateListDrawable; public class Main { public static StateListDrawable getPressedSelector(Context context, int idPressed, int idNormal) { StateListDrawable bg = new StateListDrawable(); Drawable normal = idNormal == -1 ? null : context.getResources() .getDrawable(idNormal);/*w w w .ja v a2 s . c o m*/ Drawable pressed = idPressed == -1 ? null : context.getResources() .getDrawable(idPressed); bg.addState(new int[] { android.R.attr.state_pressed, android.R.attr.state_pressed }, pressed); bg.addState(new int[] { android.R.attr.state_pressed, android.R.attr.state_focused }, pressed); bg.addState(new int[] {}, normal); return bg; } }