I want imageview to become brighter when an user presses (clicks) it, but without an additional image for that state. Is it possible? We know we have selectors where 2 different images can be used, but I would like to have a selector, a drawable from XML, and one real image.
Asked
Active
Viewed 2,050 times
1
-
1You mi8 achieve it by altering your alpha value of the image dynamically – Manoj Kumar Sep 24 '12 at 14:05
-
But in Java code, onTouch or on click? – Yar Sep 24 '12 at 14:10
-
1Thanks. On touch rather - so that I can revert it to the normal state. – Yar Sep 24 '12 at 14:12
-
ya, hopefully it helps:) – Manoj Kumar Sep 25 '12 at 05:04
2 Answers
0
Bitmap bitmap;
Drawable drawableBitmap= new BitmapDrawable(bitmap);
drawableBitmap.SetAlpha(--change here--);
convert image to drawable. set alpha.

samuelesque
- 1,165
- 13
- 30
0
OK, I got it working. Add
implements OnTouchListener
to the definition of your activity, add
.setOnTouchListener(this);
to all your imageviews that must respond to click with getting brighter, and add:
@Override
public boolean onTouch(View pV, MotionEvent pEvent) {
if(pEvent.getAction() == MotionEvent.ACTION_DOWN){
((ImageView)pV).setAlpha(128);
}
else if(pEvent.getAction() == MotionEvent.ACTION_UP){
((ImageView)pV).setAlpha(255);
}
return true;
}
to your activity. That's all.

Yar
- 4,543
- 2
- 35
- 42
-
1This doesn't appear to work with bitmap drawables. See @dotsamuelswan answer and: http://stackoverflow.com/questions/5118894/set-alpha-of-bitmap-image – greg7gkb Jul 12 '13 at 23:58