Replace selector images programmatically

As far as I’ve been able to find (I’ve tried doing something similar myself), there’s no way to modify a single state after the StateListDrawable has already been defined. You can, however, define a NEW one through code: StateListDrawable states = new StateListDrawable(); states.addState(new int[] {android.R.attr.state_pressed}, getResources().getDrawable(R.drawable.pressed)); states.addState(new int[] {android.R.attr.state_focused}, getResources().getDrawable(R.drawable.focused)); states.addState(new int[] { }, … Read more

setBackground vs setBackgroundDrawable (Android)

It’s deprecated but it still works so you could just use it. But if you want to be completly correct, just for the completeness of it… You’d do something like following: int sdk = android.os.Build.VERSION.SDK_INT; if(sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) { setBackgroundDrawable(); } else { setBackground(); } For this to work you need to set buildTarget api … Read more

Understanding the Use of ColorMatrix and ColorMatrixColorFilter to Modify a Drawable’s Hue

This is what I use for my game. This is the compilation of various part found on various articles on websites. Credits goes to the original author from the @see links. Note that a lot more can be done with color matrices. Including inverting, etc… public class ColorFilterGenerator { /** * Creates a HUE ajustment … Read more