Android: changing the pressed/focused ressource by code
I am using some tweaks that allow the user to change the UI of my application with ressources from their SDCard. That's really easy and nothing special, I just use the "setImageDrawable" or "setImageBitmap".
http://developer.android.com/reference/android/widget/ImageButton.html
That's really cool and all my users are happy to customize the UI.
But now, I would like to also change the pressed/focused ressource of the button!
Now, when they click on it, they cannot see anything and they click maybe 10 times. And more problematic, that's not really intuitive.
So i would like to change 开发者_Python百科also the pressed/focused state programmatically...
Ani idea suggestion?
You'll have to make all of your ImageButtons have a StateListDrawable instead of BitmapDrawables.
ImageButton ib = new ImageButton(this);
StateListDrawable sl = new StateListDrawable();
sl.addState(new int[] { android.R.attr.state_enabled }, yourDefaultDrawableHere);
sl.addState(new int[] { android.R.attr.state_pressed, android.R.attr.state_selected }, yourImageDrawableHere);
ib.setImageDrawable(sl);
精彩评论