A good example of this is either on the Twitter launch screen (the screen with the large icons that is seen when the application is first launch) or even just look at the application tray when you focus an application icon.
Basically I need to highlight an ImageView where the highlight contours to the image within the ImageView and looks like it's a border to that image. I would also like to customize the highlight to have it be a certain color and for it to fade out.
Thanks,
groomsy
For displaying dynamic images you can use a LayerDrawable for the image source.
Only to complete Josh Clemm answer. You can also maintain the same image defined by src, but change or highlight only the background. This would more or less like this:
logo_box.xml
And then defining the background of your button as logo_box:
Where background_normal and background_pressed can be as complex as you want, or as simple as a @color :)
I put together small library that should help with that: https://github.com/noveogroup/Highlightify
Basically it creates selector in runtime, and it should be really easy to use. Though, focused state not supported yet...
You need to assign the
src
attribute of theImageView
a state list drawable. In other words, that state list would have a different image for selected, pressed, not selected, etc. - that's how the Twitter App does it.So if you had an ImageView:
The src drawable (title_logo.xml) would look like this:
The Google IO Schedule app has a good example of this.
I noticed that a drawable xml is not enough:
An ImageView doesn't press. You should also assign an
OnClickListener
for an ImageView. Then it will press as a button.If you don't have another drawable for the pressed state you can use
setColorFilter
to achieve a simple tint effect.It behaves just like pressed state selector so when the image is pressed it changes the background to light grey color.
It handles moving finger outside the view boundaries, thus if it occurs, it restores a default background.
It's important to return
false
fromonTouch
method when you want to supportonClickListner
too.