Thanks. This sounds interesting but I'll go for the other solution, because it's very easy to implement and it worked. But I might use this one for other things.
Am Dienstag, 26. Februar 2013 09:31:01 UTC+1 schrieb skink: > > > > On 25 Lut, 23:51, user123 <[email protected]> wrote: > > I want to apply certain transforms to a view and it's children during > > pressed state, e.g. a color filter. > > > > As far my current knowledge, I can't do this using StateListDrawable or > XML > > configuration. > > > > The concrete situation: A GridView where the cells have a background > > drawable, an ImageView, and text. When the user is pressing a cell, I > want > > to change the background, to apply a PorterDuff color filter to the > image, > > and change the color of the text. The images are downloaded from the > web. > > > > > > Does anybody have an advice for this? > > > > Thanks in advance. > > step #1: override getView in your adapter > step #2: before returning your grid item set its Drawable to: > > GridDrawable d = new GridDrawable(); > v.setBackgroundDrawable(d); > return v; > > step#3: create GridDrawable class: > > class GridDrawable extends Drawable { > > @Override > protected boolean onStateChange(int[] state) { > String st = StateSet.dump(state); > Log.d(TAG, "onStateChange " + st); > // set the color fileter if state is either: > // {android.R.attr.state_selected} or > // {android.R.attr.state_pressed} > return false; > } > > @Override > public boolean isStateful() { > return true; > } > > @Override > public void draw(Canvas canvas) { > } > > @Override > public void setAlpha(int alpha) { > } > > @Override > public void setColorFilter(ColorFilter cf) { > } > > @Override > public int getOpacity() { > return PixelFormat.TRANSLUCENT; > } > } > > pskink > -- -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en --- You received this message because you are subscribed to the Google Groups "Android Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.

