As an exercise, I am trying to extend ImageButton to add some features I think would be useful. One, in particular, is a drow shadow. I’ve hit the proverbial wall with this one.
It seems to me, that a class extending BitmapDrawable is necessary. This class contains a Paint object used to draw the bitmap to the screen. If I had access to this Paint object… all I would have to do is call it’s setShadowLayer() method… but, alas, it is private. There is a public method, getPaint() that will return the paint object, but any modifications to it would be useless unless there were a corresponding setPaint() method. (There isn’t.)
Currently, my thought process looks something like the following…
- Create class
ShadowBitmapDrawablewhichextends BitmapDrawable - Within this class, somehow alter the
BitmapDrawable‘sPaintobject withPaint‘ssetShadowLayer()method. - In my custom
ImageButtonclass, callsetImageDrawable(Drawable d), and pass it myShadowBitmapDrawableobject.
Step 2 is the road block. What can I do to change BitmapDrawable‘s Paint object? Note that I added my thought process only as an indicator of where I am in this problem. I am open to other suggestions.
Here are some references:
- BitmapDrawable source (extends
Drawableto draw bitmaps) - ImageView source (base class of
ImageButton) - Drawable source
P.S. I have a bad feeling I already know the answer I’m going to get, and I’m not going to like it. Thought I’d post the question anyways and hope for the best.
Clone
BitmapDrawableinto your project, refactor it into your own package, make the data memberprotected(or provide aprotectedsetter or something), use your modifiedBitmapDrawable, and test the heck out of it.